项目运行过程中可预计且无法避免的异常
其他异常(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; }}
经验总结扩展阅读
-
-
-
-
-
-
-
-
2023年1月24日是打水井吉日吗 2023年1月24日是打水井的黄道吉日吗
-
连衣裙|有一种“整容”叫霍尊,长发飘飘欲仙,看到短发后:早剪早火了
-
北辙南辕|《北辙南辕》五对情侣,五种结局:拎清“这三样”,我们会幸福
-
-
-
-
美颜 亚洲人真的适合大地色眼影吗?真正的答案可能出乎意料
-
-
家中若有这3星座10月贵人多多 好事连连生活再无忧愁
-
-
杜江 杜江首次回应出轨,网友炸了:霍思燕你后悔了吗?
-
-