Class ExceptionHandlerMethodResolver
java.lang.Object
org.springframework.web.method.annotation.ExceptionHandlerMethodResolver
Discovers @ExceptionHandler methods in a given class,
 including all of its superclasses, and helps to resolve a given 
Exception
 and MediaType requested by clients to combinations supported by a given Method.
 This resolver will use the exception information declared as @ExceptionHandler
 annotation attributes, or as a method argument as a fallback. This will throw
 IllegalStateException instances if:
 
- No Exception information could be found for a method
 - An invalid 
MediaTypehas been declared as@ExceptionHandlerattribute - Multiple handlers declare the same exception + media type mapping
 
- Since:
 - 3.1
 - Author:
 - Rossen Stoyanchev, Juergen Hoeller, Sam Brannen, Brian Clozel
 
- 
Constructor Summary
ConstructorsConstructorDescriptionExceptionHandlerMethodResolver(Class<?> handlerType) A constructor that findsExceptionHandlermethods in the given type. - 
Method Summary
Modifier and TypeMethodDescriptionbooleanWhether the contained type has any exception mappings.resolveExceptionMapping(Throwable exception, MediaType mediaType) resolveExceptionMappingByExceptionType(Class<? extends Throwable> exceptionType, MediaType mediaType) Find aMethodto handle the given exception type and media type.resolveMethod(Exception exception) Find aMethodto handle the given exception.resolveMethodByExceptionType(Class<? extends Throwable> exceptionType) Find aMethodto handle the given exception type.resolveMethodByThrowable(Throwable exception) Find aMethodto handle the given Throwable. 
- 
Constructor Details
- 
ExceptionHandlerMethodResolver
A constructor that findsExceptionHandlermethods in the given type.- Parameters:
 handlerType- the type to introspect- Throws:
 IllegalStateException- in case of invalid or ambiguous exception mapping declarations
 
 - 
 - 
Method Details
- 
hasExceptionMappings
public boolean hasExceptionMappings()Whether the contained type has any exception mappings. - 
resolveMethod
Find aMethodto handle the given exception.Uses
ExceptionDepthComparatorif more than one match is found.- Parameters:
 exception- the exception- Returns:
 - a Method to handle the exception, or 
nullif none found 
 - 
resolveMethodByThrowable
Find aMethodto handle the given Throwable.Uses
ExceptionDepthComparatorif more than one match is found.- Parameters:
 exception- the exception- Returns:
 - a Method to handle the exception, or 
nullif none found - Since:
 - 5.0
 
 - 
resolveExceptionMapping
@Nullable public ExceptionHandlerMappingInfo resolveExceptionMapping(Throwable exception, MediaType mediaType) Find aMethodto handle the given Throwable for the requestedMediaType.Uses
ExceptionDepthComparatorandMediaType.isMoreSpecific(MimeType)if more than one match is found.- Parameters:
 exception- the exceptionmediaType- the media type requested by the HTTP client- Returns:
 - a Method to handle the exception, or 
nullif none found - Since:
 - 6.2
 
 - 
resolveMethodByExceptionType
Find aMethodto handle the given exception type. This can be useful if anExceptioninstance is not available (for example, for tools).Uses
ExceptionDepthComparatorif more than one match is found.- Parameters:
 exceptionType- the exception type- Returns:
 - a Method to handle the exception, or 
nullif none found 
 - 
resolveExceptionMappingByExceptionType
@Nullable public ExceptionHandlerMappingInfo resolveExceptionMappingByExceptionType(Class<? extends Throwable> exceptionType, MediaType mediaType) Find aMethodto handle the given exception type and media type. This can be useful if anExceptioninstance is not available (for example, for tools).- Parameters:
 exceptionType- the exception typemediaType- the media type requested by the HTTP client- Returns:
 - a Method to handle the exception, or 
nullif none found 
 
 -