0

I am new to spring framework and wanted to know which would be the best place to implement exception handling logic - controller or service? Or if it should be done at all the layers in my code?

1

1 Answer 1

1

It is best practice to handle exceptions wherever it is encountered. If i focus on question in thread, it should be handled on both cases i.e. controller and services along with other places where there is possibility of exception.

For controller point of view i would suggest use Global Exception Handling With ControllerAdvice, even if one is using controlleradvice should also handle exception in service, utils, handlers and other classes.

Refrences: https://dzone.com/articles/global-exception-handling-with-controlleradvice

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.