运行期异常
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* 运行期异常,一般来说是客户无法恢复的异常 发生异常时自动进行日志记录
*
* 捕捉该异常后,可以通过getValueInfo()获取提示信息,若想获取原始异常信息则通过getMessage()进行;
*
* @author FiliRon
* @see
*/
public abstract class UnCheckedException extends RuntimeException {
protected static final Log logger = LogFactory
.getLog(UnCheckedException.class);
/**
* 根异常
*/
private Throwable cause;
/**
* 经过翻译的界面友好的提示信息
*/
private String valueInfo;
public UnCheckedException(String msg) {
super(msg);
if (logger.isDebugEnabled()) {
logger.debug(getMessage());
}
this.valueInfo = msg;
}
public UnCheckedException(String msg, Throwable ex) {
super(msg);
this.cause = ex;
if (logger.isDebugEnabled()) {
logger.debug(getMessage());
}
this.valueInfo = 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 getValueInfo() {
return this.valueInfo;
}
}
没有评论:
发表评论