项目运行过程中可预计且无法避免的异常
其他异常(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; }}
经验总结扩展阅读
-
-
-
-
-
-
moss时尚圈过年了!来“蹦迪”的明星们用了什么?
-
-
抑郁症患者 抑郁症:若想走向康复与强大,你必须学会与自己的灵魂对话
-
2023年1月9日安装门户好吗 2023年1月9日是安装门户的黄道吉日吗
-
2022年农历腊月初七开学典礼吉日 2022年12月29日适合开学典礼吗
-
-
温州|行拘+退学处理!温州高校深夜通报两起男生骚扰女性事件处理进展
-
-
-
-
-
vivoT1和荣耀50哪个好_vivoT1和荣耀50参数对比
-
-
许三观卖血记|活着是生命的力量,活得好是人生的态度
-