summaryrefslogtreecommitdiff
path: root/spring-web/src/main/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolver.java
diff options
context:
space:
mode:
Diffstat (limited to 'spring-web/src/main/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolver.java')
-rw-r--r--spring-web/src/main/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolver.java20
1 files changed, 14 insertions, 6 deletions
diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolver.java b/spring-web/src/main/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolver.java
index 5d307cba..c121f575 100644
--- a/spring-web/src/main/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolver.java
+++ b/spring-web/src/main/java/org/springframework/web/method/annotation/ExceptionHandlerMethodResolver.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,6 +38,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
* to the exception types supported by a given {@link Method}.
*
* @author Rossen Stoyanchev
+ * @author Juergen Hoeller
* @since 3.1
*/
public class ExceptionHandlerMethodResolver {
@@ -98,8 +99,8 @@ public class ExceptionHandlerMethodResolver {
}
protected void detectAnnotationExceptionMappings(Method method, List<Class<? extends Throwable>> result) {
- ExceptionHandler annot = AnnotationUtils.findAnnotation(method, ExceptionHandler.class);
- result.addAll(Arrays.asList(annot.value()));
+ ExceptionHandler ann = AnnotationUtils.findAnnotation(method, ExceptionHandler.class);
+ result.addAll(Arrays.asList(ann.value()));
}
private void addExceptionMapping(Class<? extends Throwable> exceptionType, Method method) {
@@ -124,7 +125,14 @@ public class ExceptionHandlerMethodResolver {
* @return a Method to handle the exception, or {@code null} if none found
*/
public Method resolveMethod(Exception exception) {
- return resolveMethodByExceptionType(exception.getClass());
+ Method method = resolveMethodByExceptionType(exception.getClass());
+ if (method == null) {
+ Throwable cause = exception.getCause();
+ if (cause != null) {
+ method = resolveMethodByExceptionType(cause.getClass());
+ }
+ }
+ return method;
}
/**
@@ -133,7 +141,7 @@ public class ExceptionHandlerMethodResolver {
* @param exceptionType the exception type
* @return a Method to handle the exception, or {@code null} if none found
*/
- public Method resolveMethodByExceptionType(Class<? extends Exception> exceptionType) {
+ public Method resolveMethodByExceptionType(Class<? extends Throwable> exceptionType) {
Method method = this.exceptionLookupCache.get(exceptionType);
if (method == null) {
method = getMappedMethod(exceptionType);
@@ -145,7 +153,7 @@ public class ExceptionHandlerMethodResolver {
/**
* Return the {@link Method} mapped to the given exception type, or {@code null} if none.
*/
- private Method getMappedMethod(Class<? extends Exception> exceptionType) {
+ private Method getMappedMethod(Class<? extends Throwable> exceptionType) {
List<Class<? extends Throwable>> matches = new ArrayList<Class<? extends Throwable>>();
for (Class<? extends Throwable> mappedException : this.mappedMethods.keySet()) {
if (mappedException.isAssignableFrom(exceptionType)) {