SpringMVC统一异常处理

2021-05-03 04:29

阅读:488

标签:pre   highlight   lex   classname   指针   ret   算数   tac   下标越界   

/**
 * @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("下标越界异常");
    }
}

  

SpringMVC统一异常处理

标签:pre   highlight   lex   classname   指针   ret   算数   tac   下标越界   

原文地址:https://www.cnblogs.com/wwjj4811/p/13199964.html


评论


亲,登录后才可以留言!