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 Answer
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