异常封装
业务异常
package com.sinldo.devops.exception;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Getter
public class BusinessRunTimeException extends RuntimeException {
private static final long serialVersionUID = 1L;
private int code;
private String reason;
public BusinessRunTimeException(int code, String reason) {
super(reason);
this.code = code;
this.reason = reason;
}
public BusinessRunTimeException(int code, String reason, Throwable throwable) {
super(reason, throwable);
this.code = code;
this.reason = reason;
}
}
参数校验异常
package com.jsh.erp.exception;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Getter
public class BusinessParamCheckingException extends Exception {
private static final long serialVersionUID = 1L;
private int code;
private String reason;
public BusinessParamCheckingException(int code, String reason) {
super(reason);
this.code = code;
this.reason = reason;
}
public BusinessParamCheckingException(int code, String reason, Throwable throwable) {
super(reason, throwable);
this.code = code;
this.reason = reason;
}
}
异常分类
参数异常
系统异常
/**
* 数据写入异常
*/
public static final int DATA_WRITE_FAIL_CODE = 300;
public static final String DATA_WRITE_FAIL_MSG = "数据写入异常";
/**
* 数据查询异常
*/
public static final int DATA_READ_FAIL_CODE = 301;
public static final String DATA_READ_FAIL_MSG = "数据查询异常";
业务异常
未知异常