Handling exception Resolver - Java-Springs

HandlerExceptionResolver

Spring Handler Exception Resolvers ease the pain of unexpected exceptions that occur while your request is handled by a controller that matched the request. Handler Exception Resolvers somewhat resemble the exception mappings you can define in the web application descriptor web.xml. However, they provide a more flexible way to handle exceptions.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).

Besides implementing the Handler Exception Resolver interface, which is only a matter of implementing the resolve Exception( Exception, Handler) method and returning a Model And View, you may also use the Simple Mapping Exception Resolver.This resolver 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.

By default, the Dispatcher Servlet registers the Default Handler Exception Resolver. This resolver handles certain standard Spring MVC exceptions by setting a specific response status code:

Table:-

exceptions-from-different-handlers

HandlerExceptionResolver

Spring Handler Exception Resolvers ease the pain of un expected exceptions that occur while your request is handled by a controller that matched the request. Handler Exception Resolvers somewhat resemble the exception mappings you can define in the web application descriptor web.xml.However, they provide a more flexible way to handle exceptions.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).

Besides implementing the Handler Exception Resolver interface, which is only a matter of implementing the resolve Exception (Exception, Handler) method and returning a ModelAndView, you may also use the Simple Mapping Exceptio Resolver. This resolver 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.

By default, the Dispatcher Servlet registers the Default Handler Exception Resolver. This resolver handles certain standard Spring MVC exceptions by setting a specific response status code:

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Java-Springs Topics