全局异常处理配置
@ControllerAdvice //aop
public class GlobalExceptionHandler {
@ExceptionHandler(Exception.class)
@ResponseBody
public Result error(Exception e) {
e.printStackTrace();
return Result.fail(null).message("执行全局异常处理");
}
//特定异常处理ArithmeticException
@ExceptionHandler(ArithmeticException.class)
@ResponseBody
public Result error(ArithmeticException e) {
System.out.println("特定.....");
e.printStackTrace();
return Result.fail(null).message("执行ArithmeticException异常处理");
}
//自定义异常处理GgktException
@ExceptionHandler(GgktException.class)
@ResponseBody
public Result error(GgktException e) {
e.printStackTrace();
return Result.fail(null).code(e.getCode()).message(e.getMsg());
}
}
标签:处理,配置,ArithmeticException,class,Result,全局,异常,public
From: https://www.cnblogs.com/mikasa9826/p/17218357.html