ExceptionHandlerExceptionResolver (Spring Framework 3.2.1.RELEASE API)
Date: 2013-01-24

org.springframework.web.servlet.mvc.method.annotation

## Class ExceptionHandlerExceptionResolver

- java.lang.Object
- - org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver
  - - org.springframework.web.servlet.handler.AbstractHandlerMethodExceptionResolver
    - - org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver

- All Implemented Interfaces:
    Aware, InitializingBean, ApplicationContextAware, Ordered, HandlerExceptionResolver

      public class ExceptionHandlerExceptionResolver
      extends AbstractHandlerMethodExceptionResolver
      implements InitializingBean, ApplicationContextAware

  An `AbstractHandlerMethodExceptionResolver` that resolves exceptions through `@ExceptionHandler` methods.

  Support for custom argument and return value types can be added via `setCustomArgumentResolvers(java.util.List<org.springframework.web.method.support.HandlerMethodArgumentResolver>)` and `setCustomReturnValueHandlers(java.util.List<org.springframework.web.method.support.HandlerMethodReturnValueHandler>)`. Or alternatively to re-configure all argument and return value types use `setArgumentResolvers(java.util.List<org.springframework.web.method.support.HandlerMethodArgumentResolver>)` and `setReturnValueHandlers(List)`.

  Since:
    3.1
  Author:
    Rossen Stoyanchev

- - ### Field Summary

    - ### Fields inherited from class org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver

      `logger`

    - ### Fields inherited from interface org.springframework.core.Ordered

      `HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ExceptionHandlerExceptionResolver()` Default constructor.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `afterPropertiesSet()` Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).
    `protected ModelAndView` | `doResolveHandlerMethodException(HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod, Exception exception)` Find an `@ExceptionHandler` method and invoke it to handle the raised exception.
    `ApplicationContext` | `getApplicationContext()`
    `HandlerMethodArgumentResolverComposite` | `getArgumentResolvers()` Return the configured argument resolvers, or possibly `null` if not initialized yet via `afterPropertiesSet()`.
    `List<HandlerMethodArgumentResolver>` | `getCustomArgumentResolvers()` Return the custom argument resolvers, or `null`.
    `List<HandlerMethodReturnValueHandler>` | `getCustomReturnValueHandlers()` Return the custom return value handlers, or `null`.
    `protected List<HandlerMethodArgumentResolver>` | `getDefaultArgumentResolvers()` Return the list of argument resolvers to use including built-in resolvers and custom resolvers provided via `setCustomArgumentResolvers(java.util.List<org.springframework.web.method.support.HandlerMethodArgumentResolver>)`.
    `protected List<HandlerMethodReturnValueHandler>` | `getDefaultReturnValueHandlers()` Return the list of return value handlers to use including built-in and custom handlers provided via `setReturnValueHandlers(java.util.List<org.springframework.web.method.support.HandlerMethodReturnValueHandler>)`.
    `protected ServletInvocableHandlerMethod` | `getExceptionHandlerMethod(HandlerMethod handlerMethod, Exception exception)` Find an `@ExceptionHandler` method for the given exception.
    `List<HttpMessageConverter<?>>` | `getMessageConverters()` Return the configured message body converters.
    `HandlerMethodReturnValueHandlerComposite` | `getReturnValueHandlers()` Return the configured handlers, or possibly `null` if not initialized yet via `afterPropertiesSet()`.
    `void` | `setApplicationContext(ApplicationContext applicationContext)` Set the ApplicationContext that this object runs in.
    `void` | `setArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers)` Configure the complete list of supported argument types thus overriding the resolvers that would otherwise be configured by default.
    `void` | `setContentNegotiationManager(ContentNegotiationManager contentNegotiationManager)` Set the `ContentNegotiationManager` to use to determine requested media types.
    `void` | `setCustomArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers)` Provide resolvers for custom argument types.
    `void` | `setCustomReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers)` Provide handlers for custom return value types.
    `void` | `setMessageConverters(List<HttpMessageConverter<?>> messageConverters)` Set the message body converters to use.
    `void` | `setReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers)` Configure the complete list of supported return value types thus overriding handlers that would otherwise be configured by default.

    - ### Methods inherited from class org.springframework.web.servlet.handler.AbstractHandlerMethodExceptionResolver

      `doResolveException, shouldApplyTo`

    - ### Methods inherited from class org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver

      `buildLogMessage, getOrder, logException, prepareResponse, preventCaching, resolveException, setMappedHandlerClasses, setMappedHandlers, setOrder, setPreventResponseCaching, setWarnLogCategory`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ExceptionHandlerExceptionResolver

          public ExceptionHandlerExceptionResolver()

      Default constructor.

  - ### Method Detail

    - #### setCustomArgumentResolvers

          public void setCustomArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers)

      Provide resolvers for custom argument types. Custom resolvers are ordered after built-in ones. To override the built-in support for argument resolution use `setArgumentResolvers(java.util.List<org.springframework.web.method.support.HandlerMethodArgumentResolver>)` instead.

    - #### getCustomArgumentResolvers

          public List<HandlerMethodArgumentResolver> getCustomArgumentResolvers()

      Return the custom argument resolvers, or `null`.

    - #### setArgumentResolvers

          public void setArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers)

      Configure the complete list of supported argument types thus overriding the resolvers that would otherwise be configured by default.

    - #### getArgumentResolvers

          public HandlerMethodArgumentResolverComposite getArgumentResolvers()

      Return the configured argument resolvers, or possibly `null` if not initialized yet via `afterPropertiesSet()`.

    - #### setCustomReturnValueHandlers

          public void setCustomReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers)

      Provide handlers for custom return value types. Custom handlers are ordered after built-in ones. To override the built-in support for return value handling use `setReturnValueHandlers(java.util.List<org.springframework.web.method.support.HandlerMethodReturnValueHandler>)`.

    - #### getCustomReturnValueHandlers

          public List<HandlerMethodReturnValueHandler> getCustomReturnValueHandlers()

      Return the custom return value handlers, or `null`.

    - #### setReturnValueHandlers

          public void setReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers)

      Configure the complete list of supported return value types thus overriding handlers that would otherwise be configured by default.

    - #### getReturnValueHandlers

          public HandlerMethodReturnValueHandlerComposite getReturnValueHandlers()

      Return the configured handlers, or possibly `null` if not initialized yet via `afterPropertiesSet()`.

    - #### setMessageConverters

          public void setMessageConverters(List<HttpMessageConverter<?>> messageConverters)

      Set the message body converters to use.

      These converters are used to convert from and to HTTP requests and responses.

    - #### getMessageConverters

          public List<HttpMessageConverter<?>> getMessageConverters()

      Return the configured message body converters.

    - #### setContentNegotiationManager

          public void setContentNegotiationManager(ContentNegotiationManager contentNegotiationManager)

      Set the `ContentNegotiationManager` to use to determine requested media types. If not set, the default constructor is used.

    - #### setApplicationContext

          public void setApplicationContext(ApplicationContext applicationContext)
                                     throws BeansException

      Description copied from interface: `ApplicationContextAware`
      Set the ApplicationContext that this object runs in. Normally this call will be used to initialize the object.

      Invoked after population of normal bean properties but before an init callback such as `InitializingBean.afterPropertiesSet()` or a custom init-method. Invoked after `ResourceLoaderAware.setResourceLoader(org.springframework.core.io.ResourceLoader)`, `ApplicationEventPublisherAware.setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher)` and `MessageSourceAware`, if applicable.

      Specified by:
        `setApplicationContext` in interface `ApplicationContextAware`
      Parameters:
        `applicationContext` - the ApplicationContext object to be used by this object
      Throws:
        `ApplicationContextException` - in case of context initialization errors
        `BeansException` - if thrown by application context methods
      See Also:
        `BeanInitializationException`

    - #### getApplicationContext

          public ApplicationContext getApplicationContext()

    - #### afterPropertiesSet

          public void afterPropertiesSet()

      Description copied from interface: `InitializingBean`
      Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).

      This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.

      Specified by:
        `afterPropertiesSet` in interface `InitializingBean`

    - #### getDefaultArgumentResolvers

          protected List<HandlerMethodArgumentResolver> getDefaultArgumentResolvers()

      Return the list of argument resolvers to use including built-in resolvers and custom resolvers provided via `setCustomArgumentResolvers(java.util.List<org.springframework.web.method.support.HandlerMethodArgumentResolver>)`.

    - #### getDefaultReturnValueHandlers

          protected List<HandlerMethodReturnValueHandler> getDefaultReturnValueHandlers()

      Return the list of return value handlers to use including built-in and custom handlers provided via `setReturnValueHandlers(java.util.List<org.springframework.web.method.support.HandlerMethodReturnValueHandler>)`.

    - #### doResolveHandlerMethodException

          protected ModelAndView doResolveHandlerMethodException(HttpServletRequest request,
                                                     HttpServletResponse response,
                                                     HandlerMethod handlerMethod,
                                                     Exception exception)

      Find an `@ExceptionHandler` method and invoke it to handle the raised exception.
      Specified by:
        `doResolveHandlerMethodException` in class `AbstractHandlerMethodExceptionResolver`
      Parameters:
        `request` - current HTTP request
        `response` - current HTTP response
        `handlerMethod` - the executed handler method, or `null` if none chosen at the time of the exception (for example, if multipart resolution failed)
        `exception` - the exception that got thrown during handler execution
      Returns:
        a corresponding ModelAndView to forward to, or `null` for default processing

    - #### getExceptionHandlerMethod

          protected ServletInvocableHandlerMethod getExceptionHandlerMethod(HandlerMethod handlerMethod,
                                                                Exception exception)

      Find an `@ExceptionHandler` method for the given exception. The default implementation searches methods in the class hierarchy of the controller first and if not found, it continues searching for additional `@ExceptionHandler` methods assuming some @ControllerAdvice Spring-managed beans were detected.
      Parameters:
        `handlerMethod` - the method where the exception was raised, possibly `null`
        `exception` - the raised exception
      Returns:
        a method to handle the exception, or `null`