📄 baseexception.java
字号:
package com.pegasus.framework.exception;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.pegasus.framework.util.ExceptionUtil;
public class BaseException extends Exception {
private Log log = LogFactory.getLog(BaseException.class);
private Throwable cause = null;
/**
* Constructor.
* @param msg error message.
*/
public BaseException(String msg) {
super(msg);
log.fatal(msg);
}
/**
* Constructor.
* @param cause the nested exception (caused by).
*/
public BaseException(Throwable cause) {
super();
this.cause = cause;
log.fatal(" <---- Caused by: " + cause.toString() + " ---->", cause);
}
/**
* Constructor.
* @param msg error message.
* @param cause the nested exception (caused by).
*/
public BaseException(String msg, Throwable cause) {
super(msg);
this.cause = cause;
log.fatal(msg + " <---- Caused by: " + cause.toString() + " ---->", cause);
}
/**
* Gets the causing exception, if any.
*/
public Throwable getCausedByException() {
return cause;
}
public String toString() {
if (cause == null) {
return super.toString();
} else {
return super.toString() + " <---- Caused by: " + cause.toString() + " ---->";
}
}
public void printStackTrace() {
if (cause != null) {
log.error(ExceptionUtil.formatTrace(cause));
}
}
public void printStackTrace(java.io.PrintStream ps) {
super.printStackTrace(ps);
if (cause != null) {
ps.println("<---- Caused by:");
cause.printStackTrace(ps);
ps.println("---->");
}
}
public void printStackTrace(java.io.PrintWriter pw) {
super.printStackTrace(pw);
if (cause != null) {
pw.println("<---- Caused by:");
cause.printStackTrace(pw);
pw.println("---->");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -