I am in reference to Spring MVC's @ExceptionHandler annotation.
I would like for my @ExceptionHandler-annotated method to handle all exception but one or two specific exceptions that would be ignored.
Is this possible with the Spring MVC 3.2? Is there any workaround?
Why not add two handler methods like
@ExceptionHandler(value={Exception.class})
public ModelAndView all(){
return new ModelAndView();//return general M&V
}
@ExceptionHandler(value={Ex1.class, Ex2.class})
public ModelAndView special(){
return new ModelAndView();//return special M&V
}
I don't think there is a way to do that with the @ExceptionHandler annotation.
One approach that should work is for you to provide an implementation of the HandlerExceptionResolver interface. In your implementation you could provide the code from your @ExceptionHandler methods and only execute it for the Exceptions that you wish to handle.
I think for Spring MVC to pick-up your custom HandlerExceptionResolver, it will just need to be registered as a bean within your ApplicationContext.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With