We have learnt how to handle exception using the Spring exception handling mechanism through my previous articles and we know how the @ControllerAdvice and @ExceptionHandler annotations works, how to handle exception globally. Now lets see how do we handle a User defined Exception.
In my previous article you would have learnt how to handle exception using @ExceptionHandler but that way of handling exceptions have a slight drawback as you have to write exception handling methods for each controller, suppose if you have 3 controllers each one should have its own exception handling methods. There no other way to have it globally. To overcome this, In Spring 3.2 they have introduced something called as @ControllerAdvice which acts a Global Exception Handler for all the controller you have. [Read more…]
A good web application should have the perfect exception handling mechanism, so that the user will not be rendered with any unhandled exception thrown. Spring MVC provides a great way to handle these exception with the help of @ExceptionHandler annotation. We simply have to annotate a method with @ExceptionHandler annotation and that method will be called automatically when the exception occured. Let’s see how Spring handles exception. [Read more…]