SpringMVC统一异常处理
2021-05-03 04:29
标签:pre highlight lex classname 指针 ret 算数 tac 下标越界 SpringMVC统一异常处理 标签:pre highlight lex classname 指针 ret 算数 tac 下标越界 原文地址:https://www.cnblogs.com/wwjj4811/p/13199964.html/**
* @author wen.jie
* @Classname GlobalExceptionHandler
* @Description 统一异常处理
* @Date 2020/6/27
*/
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(value = {ArithmeticException.class})
public Object handlerException(Exception e){
log.info(Arrays.toString(e.getStackTrace()));
return new CommonResult().failed("数学算数异常");
}
@ExceptionHandler(value = {NullPointerException.class})
public Object handlerException2(Exception e){
log.info(Arrays.toString(e.getStackTrace()));
return new CommonResult().failed("空指针异常");
}
@ExceptionHandler(value = {IndexOutOfBoundsException.class})
public Object handlerException3(Exception e){
log.info(Arrays.toString(e.getStackTrace()));
return new CommonResult().failed("下标越界异常");
}
}