3.17.3 @ExceptionHandle注解

3.17.3 @ExceptionHandle注解

org.springframework.web.bind.annotation.ExceptionHandle注解的作用对象为方法,并且在运行时有效,value()可以指定异常类。
@ExceptionHandler注解的源代码如下:

1
2
3
4
5
6
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface ExceptionHandler{
Class<? extends Throwable>[] value() default {};
}

@ExceptionHandler注解的方法可以支持的参数除了HttpServletRequestHttpServletResponse等对象之外,还支持一个异常参数,包括一般的异常或自定义异常。
如果@ExceptionHandler注解没有指定异常类,会默认进行映射.