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
MediaType
has been declared as@ExceptionHandler
attribute - Multiple handlers declare the same exception + media type mapping
- Since:
- 3.1
- Author:
- Rossen Stoyanchev, Juergen Hoeller, Sam Brannen, Brian Clozel
-
Constructor Summary
ConstructorDescriptionExceptionHandlerMethodResolver
(Class<?> handlerType) A constructor that findsExceptionHandler
methods in the given type. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Whether the contained type has any exception mappings.resolveExceptionMapping
(Throwable exception, MediaType mediaType) resolveExceptionMappingByExceptionType
(Class<? extends Throwable> exceptionType, MediaType mediaType) Find aMethod
to handle the given exception type and media type.resolveMethod
(Exception exception) Find aMethod
to handle the given exception.resolveMethodByExceptionType
(Class<? extends Throwable> exceptionType) Find aMethod
to handle the given exception type.resolveMethodByThrowable
(Throwable exception) Find aMethod
to handle the given Throwable.
-
Constructor Details
-
ExceptionHandlerMethodResolver
A constructor that findsExceptionHandler
methods 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 aMethod
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
Find aMethod
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
-
resolveExceptionMapping
@Nullable public ExceptionHandlerMappingInfo resolveExceptionMapping(Throwable exception, MediaType mediaType) Find aMethod
to handle the given Throwable for the requestedMediaType
.Uses
ExceptionDepthComparator
andMediaType.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
null
if none found - Since:
- 6.2
-
resolveMethodByExceptionType
Find aMethod
to handle the given exception type. This can be useful if anException
instance is not available (for example, 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
-
resolveExceptionMappingByExceptionType
@Nullable public ExceptionHandlerMappingInfo resolveExceptionMappingByExceptionType(Class<? extends Throwable> exceptionType, MediaType mediaType) Find aMethod
to handle the given exception type and media type. This can be useful if anException
instance 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
null
if none found
-