Top Description Fields Constructors Methods
org.springframework.web.method.annotation

public Class ExceptionHandlerMethodResolver

extends Object
Class Inheritance
Imports
java.lang.reflect.Method, java.util.ArrayList, .Arrays, .HashMap, .List, .Map, org.springframework.core.ExceptionDepthComparator, .MethodIntrospector, org.springframework.core.annotation.AnnotatedElementUtils, org.springframework.lang.Nullable, org.springframework.util.Assert, .ConcurrentReferenceHashMap, .ReflectionUtils.MethodFilter, org.springframework.web.bind.annotation.ExceptionHandler

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.
Authors
Rossen Stoyanchev, Juergen Hoeller, Sam Brannen
Since
3.1

Field Summary

Modifier and TypeField and Description
public static final ReflectionUtils.MethodFilter
EXCEPTION_HANDLER_METHODS

A filter for selecting @ExceptionHandler methods.

private final Map<Class<? extends Throwable>, Method>
private final Map<Class<? extends Throwable>, Method>
private static final Method

Constructor Summary

AccessConstructor and Description
public
ExceptionHandlerMethodResolver(Class<?>
the type to introspect
handlerType
)

A constructor that finds ExceptionHandler methods in the given type.

Method Summary

Modifier and TypeMethod and Description
private void
addExceptionMapping(Class<? extends Throwable> exceptionType, Method method)

private void
private List<Class<? extends Throwable>>
detectExceptionMappings(Method method)

Extract exception mappings from the @ExceptionHandler annotation first, and then as a fallback from the method signature itself.

private Method
getMappedMethod(Class<? extends Throwable> exceptionType)

Return the Method mapped to the given exception type, or NO_MATCHING_EXCEPTION_HANDLER_METHOD if none.

public boolean
hasExceptionMappings()

Whether the contained type has any exception mappings.

private void
public Method

Returns:

a Method to handle the exception, or null if none found
resolveMethod
(Exception
the exception
exception
)

Find a Method to handle the given exception.

public Method

Returns:

a Method to handle the exception, or null if none found
resolveMethodByExceptionType
(Class<? extends Throwable>
the exception type
exceptionType
)

Find a Method to handle the given exception type.

public Method

Returns:

a Method to handle the exception, or null if none found
resolveMethodByThrowable
(Throwable
the exception
exception
)

Find a Method to handle the given Throwable.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

EXCEPTION_HANDLER_METHODSback to summary
public static final ReflectionUtils.MethodFilter EXCEPTION_HANDLER_METHODS

A filter for selecting @ExceptionHandler methods.

exceptionLookupCacheback to summary
private final Map<Class<? extends Throwable>, Method> exceptionLookupCache
mappedMethodsback to summary
private final Map<Class<? extends Throwable>, Method> mappedMethods
NO_MATCHING_EXCEPTION_HANDLER_METHODback to summary
private static final Method NO_MATCHING_EXCEPTION_HANDLER_METHOD

Constructor Detail

ExceptionHandlerMethodResolverback to summary
public ExceptionHandlerMethodResolver(Class<?> handlerType)

A constructor that finds ExceptionHandler methods in the given type.

Parameters
handlerType:Class<?>

the type to introspect

Method Detail

addExceptionMappingback to summary
private void addExceptionMapping(Class<? extends Throwable> exceptionType, Method method)
detectAnnotationExceptionMappingsback to summary
private void detectAnnotationExceptionMappings(Method method, List<Class<? extends Throwable>> result)
detectExceptionMappingsback to summary
private List<Class<? extends Throwable>> detectExceptionMappings(Method method)

Extract exception mappings from the @ExceptionHandler annotation first, and then as a fallback from the method signature itself.

Annotations
@SuppressWarnings:unchecked
getMappedMethodback to summary
private Method getMappedMethod(Class<? extends Throwable> exceptionType)

Return the Method mapped to the given exception type, or NO_MATCHING_EXCEPTION_HANDLER_METHOD if none.

hasExceptionMappingsback to summary
public boolean hasExceptionMappings()

Whether the contained type has any exception mappings.

noMatchingExceptionHandlerback to summary
private void noMatchingExceptionHandler()

For the NO_MATCHING_EXCEPTION_HANDLER_METHOD constant.

Annotations
@SuppressWarnings:unused
resolveMethodback to summary
public Method resolveMethod(Exception exception)

Find a Method to handle the given exception.

Uses ExceptionDepthComparator if more than one match is found.

Parameters
exception:Exception

the exception

Returns:Method

a Method to handle the exception, or null if none found

Annotations
@Nullable
resolveMethodByExceptionTypeback to summary
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:Class<? extends Throwable>

the exception type

Returns:Method

a Method to handle the exception, or null if none found

Annotations
@Nullable
resolveMethodByThrowableback to summary
public Method resolveMethodByThrowable(Throwable exception)

Find a Method to handle the given Throwable.

Uses ExceptionDepthComparator if more than one match is found.

Parameters
exception:Throwable

the exception

Returns:Method

a Method to handle the exception, or null if none found

Annotations
@Nullable
Since
5.0