Loading

SpringMVC统一异常处理

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

  

posted @ 2020-06-27 21:32  秋风飒飒吹  阅读(483)  评论(0编辑  收藏  举报