Thursday, August 30, 2012

Spring MVC Controller Exception Handling

One of the neat things about Spring MVC 3 is that it allows you to catch exceptions via an exception handler method on that controller.  This allows you to avoid mucking up code with try catches.

To catch your Exception you need to use the @ExceptionHandler annotation.  Like most controller methods it is very flexible in what data can be accessed and returned (String/view name, ModelAndView, etc).  Here is more info here.

Here are some examples of exception handlers.

1 comment:

  1. Dude that is fantastic! Great post, going to be playing with this soon.