demo:
public class MyException extends RuntimeException {
/**
*
*/
private static final long serialVersionUID = -8716100844379461082L;
private Integer code;//自定義異常碼
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public MyException(String message, Integer code) {
super(message);// 父類的構造函數;調用底層的Throwable的構造函數,將參數message賦值到detailMessage (Throwable的屬性)
this.code = code;//賦值code碼
}
}
使用場景:
throw new MyException(code,“message”);
//有上級函數try catch 處理;