java工具类8-业务异常

BaseException:

/**
 * 异常基类<br/>
 *
 * @Date 2019年3月8日 
 * @since 1.0.0
 * 
 */
@SuppressWarnings("serial")
public abstract class BaseException extends RuntimeException {
    private IErrorCode error;

    public BaseException(Throwable cause, IErrorCode error) {
        super("[" + error.getCode() + "]" + error.getMsg(), cause);
        this.error = error;
    }

    public BaseException(Throwable cause, IErrorCode error, Object... errorValues) {
        super("[" + error.getCode() + "]" + String.format(error.getMsg(), errorValues), cause);
        this.error = error;
    }

    public IErrorCode getError() {
        return error;
    }

    public void setError(IErrorCode error) {
        this.error = error;
    }
}

ServiceException:

@SuppressWarnings("serial")
public class ServiceException extends BaseException {

    public ServiceException(Throwable cause, IErrorCode error) {
        super(cause, error);
    }

    public ServiceException(Throwable cause, IErrorCode error, Object... values) {
        super(cause, error, values);
    }
}
原文地址:https://www.cnblogs.com/chong-zuo3322/p/12855329.html