package com.tszr.controller;

import com.tszr.exception.MyException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import java.sql.SQLException;

@ControllerAdvice
public class GlobalExceptionHandlerController {
    @ExceptionHandler(value = Exception.class)
    public String handlerException(Exception e) {
        //数据库异常
        if (e instanceof SQLException) {
            return "sqlError";
        } else if (e instanceof MyException) {//自定义异常
            return "myError";
        } else {//未知异常
            return "noError";
        }
    }
}