需要检查的异常
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* 需要检查的异常,该异常一般需要捕捉进行恢复处理 发生异常时自动进行日志记录
*
* 捕捉该异常后,可以通过getValueInfo()获取提示信息,若想获取原始异常信息则通过getMessage()进行
*
* @author FiliRon
* @see
*/
public abstract class CheckedException extends Exception {
protected static final Log logger = LogFactory
.getLog(CheckedException.class);
/**
* 根异常
*/
private Throwable cause;
/**
* 经过翻译的界面友好的提示信息
*/
private String vauleInfo;
public CheckedException(String msg) {
super(msg);
if (logger.isDebugEnabled()) {
logger.debug(getMessage());
}
this.vauleInfo = msg;
}
public CheckedException(String msg, Throwable ex) {
super(msg);
this.cause = ex;
if (logger.isDebugEnabled()) {
logger.error(getMessage());
}
this.vauleInfo = msg;
}
/**
* 得到完整异常信息
*/
public String getMessage() {
if (this.cause == null || this.cause == this) {
return super.getMessage();
} else {
return super.getMessage() + ";\n嵌套异常是 "
+ this.cause.getClass().getName() + ": "
+ this.cause.getMessage();
}
}
/**
* 获取该异常友好提示信息
*
* @return
*/
public String getVauleInfo() {
return this.vauleInfo;
}
}
没有评论:
发表评论