自定义异常
This commit is contained in:
parent
7180e3dcc0
commit
a13c68f38d
30
src/main/java/cn/zhangdeman/CustomException.java
Normal file
30
src/main/java/cn/zhangdeman/CustomException.java
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package cn.zhangdeman;
|
||||||
|
|
||||||
|
// 自定义异常
|
||||||
|
public class CustomException extends RuntimeException {
|
||||||
|
private final Object code; // 错误码
|
||||||
|
private final String message; // 异常信息
|
||||||
|
private final Object data; // 异常数据
|
||||||
|
public CustomException(String message) {
|
||||||
|
super(message);
|
||||||
|
this.code = -1;
|
||||||
|
this.data = null;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据code与
|
||||||
|
public CustomException(Object code, Object data) {
|
||||||
|
this.code = code;
|
||||||
|
this.message = ""; // TODO : 根据code初始化Message
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
public CustomException(Object code, String message, Object data) {
|
||||||
|
this.code = code;
|
||||||
|
this.message = message;
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getData() {
|
||||||
|
return this.data;
|
||||||
|
}
|
||||||
|
}
|
12
src/main/java/cn/zhangdeman/CustomExceptionEnum.java
Normal file
12
src/main/java/cn/zhangdeman/CustomExceptionEnum.java
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package cn.zhangdeman;
|
||||||
|
|
||||||
|
// 自定义异常的枚举值
|
||||||
|
public enum CustomExceptionEnum {
|
||||||
|
;
|
||||||
|
private final Object code; // 异常状态码
|
||||||
|
private final String message; // 异常信息
|
||||||
|
CustomExceptionEnum(Object code, String message) {
|
||||||
|
this.code = code;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
}
|
@ -1,19 +0,0 @@
|
|||||||
package cn.zhangdeman;
|
|
||||||
|
|
||||||
// 自定义异常
|
|
||||||
public class Exception {
|
|
||||||
private final Object code; // 错误码
|
|
||||||
private final String message; // 异常信息
|
|
||||||
private final Object data; // 异常数据
|
|
||||||
|
|
||||||
public Exception(Object code, Object data) {
|
|
||||||
this.code = code;
|
|
||||||
this.message = ""; // TODO : 根据code初始化Message
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
public Exception(Object code, String message, Object data) {
|
|
||||||
this.code = code;
|
|
||||||
this.message = message;
|
|
||||||
this.data = data;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user