package com.ning.billing;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class BillingExceptionBase extends Exception {
private final static Logger log = LoggerFactory.getLogger(BillingExceptionBase.class);
private static final long serialVersionUID = 165720101383L;
private final Throwable cause;
private final int code;
private final String formattedMsg;
public BillingExceptionBase(Throwable cause, int code, final String msg) {
this.formattedMsg = msg;
this.code = code;
this.cause = cause;
}
public BillingExceptionBase(Throwable cause, ErrorCode code, final Object... args) {
String tmp = null;
try {
tmp = String.format(code.getFormat(), args);
} catch (RuntimeException e) {
log.error("Failed to format msg for error code " + code.getCode(), e);
throw e;
}
this.formattedMsg = tmp;
this.code = code.getCode();
this.cause = cause;
}
public BillingExceptionBase(ErrorCode code, final Object... args) {
this(null, code, args);
}
@Override
public String getMessage() {
return formattedMsg;
}
@Override
public Throwable getCause() {
return cause;
}
public int getCode() {
return code;
}
}