Class ExceptionHandlerMethodResolver

java.lang.Object
org.springframework.web.method.annotation.ExceptionHandlerMethodResolver

public class ExceptionHandlerMethodResolver extends Object
Discovers @ExceptionHandler methods in a given class, including all of its superclasses, and helps to resolve a given Exception to the exception types supported by a given Method.
Since:
3.1
Author:
Rossen Stoyanchev, Juergen Hoeller, Sam Brannen
  • Field Details

    • EXCEPTION_HANDLER_METHODS

      public static final ReflectionUtils.MethodFilter EXCEPTION_HANDLER_METHODS
      A filter for selecting @ExceptionHandler methods.
  • Constructor Details

    • ExceptionHandlerMethodResolver

      public ExceptionHandlerMethodResolver(Class<?> handlerType)
      A constructor that finds ExceptionHandler methods in the given type.
      Parameters:
      handlerType - the type to introspect
  • Method Details

    • hasExceptionMappings

      public boolean hasExceptionMappings()
      Whether the contained type has any exception mappings.
    • resolveMethod

      @Nullable public Method resolveMethod(Exception exception)
      Find a Method to handle the given exception.

      Uses ExceptionDepthComparator if more than one match is found.

      Parameters:
      exception - the exception
      Returns:
      a Method to handle the exception, or null if none found
    • resolveMethodByThrowable

      @Nullable public Method resolveMethodByThrowable(Throwable exception)
      Find a Method to handle the given Throwable.

      Uses ExceptionDepthComparator if more than one match is found.

      Parameters:
      exception - the exception
      Returns:
      a Method to handle the exception, or null if none found
      Since:
      5.0
    • resolveMethodByExceptionType

      @Nullable public Method resolveMethodByExceptionType(Class<? extends Throwable> exceptionType)
      Find a Method to handle the given exception type. This can be useful if an Exception instance is not available (e.g. for tools).

      Uses ExceptionDepthComparator if more than one match is found.

      Parameters:
      exceptionType - the exception type
      Returns:
      a Method to handle the exception, or null if none found