自定义一个异常
自定义若干个运行时异常,可以根据不同的错误类型定义多个
public class TestException extends RuntimeException {
private String code;
public TestException(String code) {
this.code = code;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
}
自定义异常信息类
根据需求自第一字段
public class ErrorResponse {
private String code;
private String message;
public ErrorResponse(String code, String message) {
this.code = code;
this.message = message;
}