ApiException.java
1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package cn.csbr.app.exception;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
/**
* 自定义的业务异常--需要捕获
*
* @author lid
*/
public class ApiException extends Exception {
private String errorMsg;
public ApiException() {
super("发生错误!");
this.errorMsg = "发生错误!";//默认信息
}
public ApiException(String errorMsg) {
super("发生错误!");
this.errorMsg = errorMsg;//默认信息
}
public <T> ApiException(String msg, Class<T> logObj) {
super(msg);
setErrorMsg(msg);
// 记录日志
Logger logger = LogManager.getLogger(logObj);
logger.error(msg);
}
@Override
public String getMessage() {
return super.getMessage();
}
@Override
public String toString() {
return super.toString();
}
public String getErrorMsg() {
return errorMsg;
}
public void setErrorMsg(String errorMsg) {
this.errorMsg = errorMsg;
}
}