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