在开发中,我们通常会需要处理一些异常信息,对于异常信息并不是将异常信息耦合在业务代码中,而是通过一个类将异常信息归于一个class文件中,等遇到的时候,直接通过异常信息类来说明异常信息,那么怎么来编写这个类呢,其实很简单,如下即可。
1.定义一个异常信息描述类,继承BaseExceptionInfo
2.在自定义的异常信息描述类中使用 public static final String 修饰异常信息的code和中文描述
例子如下:
public class AccountException extends **BaseExceptionInfo** {
/**
* 业务操作异常信息
*/
public static final String SUBMIT_IS_REPEAT = "00400001";
public static final String SUBMIT_IS_REPEAT_DESC = "请勿重复提交!";
public static final String CREATE_ACCOUNT_LOCK_FAIL = "00400091";
public static final String CREATE_ACCOUNT_LOCK_FAIL_DESC = "创建账户加锁失败!";
public static final String ACCOUNT_ID_IS_NULL = "00400092";
public static final String ACCOUNT_ID_IS_NULL_DESC = "账户ID不能为空!";
public static final String VALIDATE_ACCOUNT_FAIL = "00400099";
public static final String VALIDATE_ACCOUNT_FAIL_DESC = "账户验证失败!";
public static final String BANK_CARD_IS_NULL = "00400081";
public static final String BANK_CARD_IS_NULL_DESC = "银行卡ID不能为空!";
public static final String QUERY_ACCOUNT_IS_NULL = "00400082";
public static final String QUERY_ACCOUNT_IS_NULL_DESC = "查询账户为空!";
public static final String ACCOUNT_STATUS_ERROR = "00400083";
public static final String ACCOUNT_STATUS_ERROR_DESC = "账户状态异常!";
public static final String ACCOUNT_AMOUNT_LOCK_FAIL = "00400085";
public static final String ACCOUNT_AMOUNT_LOCK_FAIL_DESC = "账户余额变动加锁失败!";
public static final String PAY_PASSWORD_IS_ERROR= "00400086";
public static final String PAY_PASSWORD_IS_ERROR_DESC = "支付密码错误!";
public static final String WITHDRAW_DATA_IS_EMPTY= "00400087";
public static final String WITHDRAW_DATA_IS_EMPTY_DESC = "查询提现记录为空!";
public static final String ACCOUNT_AND_TYPE_ALL_EMPTY= "00400088";
public static final String ACCOUNT_AND_TYPE_ALL_EMPTY_DESC = "账户和类型不能同时为空!";
public static final String WITHDRAW_ID_IS_EMPTY= "00400089";
public static final String WITHDRAW_ID_IS_EMPTY_DESC = "提现ID不能为空!";
}