项目运行过程中可预计且无法避免的异常
其他异常(Exception)
对于不同的异常,我们采用不同的应对方法,我们下面做出简单的处理:
- Code状态码增加
 
package com.itheima.controller;public class Code {    public static final Integer SAVE_OK = 20011;    public static final Integer DELETE_OK = 20021;    public static final Integer UPDATE_OK = 20031;    public static final Integer GET_OK = 20041;    public static final Integer SAVE_ERR = 20010;    public static final Integer DELETE_ERR = 20020;    public static final Integer UPDATE_ERR = 20030;    public static final Integer GET_ERR = 20040;    public static final Integer SYSTEM_ERR = 50001;    public static final Integer SYSTEM_TIMEOUT_ERR = 50002;    public static final Integer SYSTEM_UNKNOW_ERR = 59999;    public static final Integer BUSINESS_ERR = 60002;}
- 书写自定义异常处理器
 
// SystemExceptionpackage com.itheima.exception;//自定义异常处理器,用于封装异常信息,对异常进行分类,需要继承RuntimeExceptionpublic class SystemException extends RuntimeException{    private Integer code;    public Integer getCode() {        return code;    }    public void setCode(Integer code) {        this.code = code;    }    public SystemException(Integer code, String message) {        super(message);        this.code = code;    }    public SystemException(Integer code, String message, Throwable cause) {        super(message, cause);        this.code = code;    }}// BusinessExceptionpackage com.itheima.exception;//自定义异常处理器,用于封装异常信息,对异常进行分类,需要继承RuntimeExceptionpublic class BusinessException extends RuntimeException{    private Integer code;    public Integer getCode() {        return code;    }    public void setCode(Integer code) {        this.code = code;    }    public BusinessException(Integer code, String message) {        super(message);        this.code = code;    }    public BusinessException(Integer code, String message, Throwable cause) {        super(message, cause);        this.code = code;    }}
		  	
经验总结扩展阅读
           - 
              
              
            
- 
              
              
            
- 
              
              
            
- 
              
              
            
- 
              
              
                  有一句俗话:“早起的鸟儿有虫吃。|早睡早起的时间,早起的人更容易获取成功机会 
 
- 
              
              
            
- 
              
              
                  8月,4大星座财运大涨,横财正财偏财齐聚满堂,富贵满堂 
 
- 
              
              
            
- 
              
              
                  裸妆|看来看去,浓妆艳抹不算啥,还是裸妆最百搭,关键实用又简单 
 
- 
              
              
            
- 
              
              
                  健康周谈|冬天是脑梗高发季,该如何度过?医生:做好4件事,或能安稳过冬 
 
- 
              
              
            
- 
              
              
            
- 
              
              
            
- 
              
              
            
- 
              
              
            
- 
              
              
                  越南|中国男性和越南男性有啥区别?听听越南姑娘是怎么说的 
 
- 
              
              
                  2023年1月4日制作房梁黄道吉日 2023年农历腊月十三制作房梁吉日 
 
- 
              
              
            
- 
              
              
                  2023年5月定亲黄道吉日 2023年5月哪天适合定亲