Spring MVC Exception Handling – @ControllerAdvice and @ExceptionHandler

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…]

Spring MVC Exception Handling – @ExceptionHandler

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…]