File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Spring and the fly likes Doubt about exceptions handling in Spring Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Doubt about exceptions handling in Spring" Watch "Doubt about exceptions handling in Spring" New topic

Doubt about exceptions handling in Spring

Nam Ha Minh
Ranch Hand

Joined: Oct 31, 2011
Posts: 484

Hi folks,

According to Spring's documentation written at:

Spring HandlerExceptionResolver implementations deal with unexpected exceptions that occur during controller execution. A HandlerExceptionResolver somewhat resembles the exception mappings you can define in the web application descriptor web.xml. However, they provide a more flexible way to do so. For example they provide information about which handler was executing when the exception was thrown. Furthermore, a programmatic way of handling exceptions gives you more options for responding appropriately before the request is forwarded to another URL (the same end result as when you use the Servlet specific exception mappings).

Look at the bold sentence. My question is how to get the information of the executing handler?

And for the next paragraph:

Besides implementing the HandlerExceptionResolver interface, which is only a matter of implementing the resolveException(Exception, Handler) method and returning a ModelAndView, you may also use the provided SimpleMappingExceptionResolver or create @ExceptionHandler methods. The SimpleMappingExceptionResolver enables you to take the class name of any exception that might be thrown and map it to a view name. This is functionally equivalent to the exception mapping feature from the Servlet API, but it is also possible to implement more finely grained mappings of exceptions from different handlers. The @ExceptionHandler annotation on the other hand can be used on methods that should be invoked to handle an exception. Such methods may be defined locally within an @Controller or may apply globally to all @RequestMapping methods when defined within an @ControllerAdvice class. The following sections explain this in more detail.

I don't understand the sentence: it is also possible to implement more finely grained mappings of exceptions from different handlers.

What does that mean, and could any one give me some examples to illustrate that statement?

Thanks in advance.

PM Me If You Want to get Urgent Help on Java Programming
I agree. Here's the link:
subject: Doubt about exceptions handling in Spring
Similar Threads
Any recipes for Exception handling
some doubts
Hiding static methods and checked exceptions
Exceptions (long one) Your response requested.
How to pass an object between MVC controllers?