diff --git a/spring/Spring core/SpringMVC.md b/spring/Spring core/SpringMVC.md index e6260df..9378e72 100644 --- a/spring/Spring core/SpringMVC.md +++ b/spring/Spring core/SpringMVC.md @@ -577,4 +577,18 @@ public class SimpleController { } } ``` +该异常参数会匹配被抛出的顶层异常(例如,被直接抛出的IOException),也会匹配被包装的内层cause(例如,被包装在IllegalStateException中的IOException)。**该参数会匹配任一层级的cause。** +> 只要@ExceptionHandler方法的异常参数类型匹配异常抛出stacktrace中任一层次的异常类型,异常都会被捕获并且处理。 +```java + @PostMapping("/shiro") + public String shiro() { + throw new RuntimeException(new JarException("fuck")); + } + + @ExceptionHandler + public String handleJarException(JarException e) { + return e.getMessage() + ", Jar"; + } +``` +> 如果有多个@ExceptionHandler方法匹配抛出的异常链,那么