异常工具类在一个系统中是比较常用的工具类,一般包含异常码,和异常提示信息,那么该如何编写一个异常工具类呢?按照下面步骤来就可以编写一个异常工具类。
public class BaseException extends RuntimeException {
public String code;
public String desc;
public BaseException() {
}
public BaseException(String code) {
this.code = code;
this.desc = ExceptionUtil.getDesc(code);
log.error(code + " - " + this.desc, super.getCause());
}
public BaseException(String code, String desc) {
this.code = code;
this.desc = desc;
log.error(code + " - " + desc, super.getCause());
}
public BaseException(String code, Exception e) {
this.code = code;
this.desc = ExceptionUtil.getDesc(code);
log.error(code + " - " + this.desc, e);
}
public BaseException(String code, String desc, Exception e) {
this.code = code;
this.desc = desc;
log.error(code + " - " + desc, e);
}
public Throwable fillInStackTrace() {
return this;
}
}