📄 cmsexception.java
字号:
* @param i Exception error code
*/
public CmsException(int type) {
this("CmsException ID: " + type, type, null, false);
}
/**
* Contructs a CmsException with the provided error code and
* a given root cause.
* The error codes used should be the constants from the CmsEception class.
*
* @param i Exception code
* @param e Forwarded root cause exception
*/
public CmsException(int type, Throwable rootCause) {
this("CmsException ID: " + type, type, rootCause, false);
}
/**
* Constructs a CmsException with the provided description.
*
* @param s Exception message
*/
public CmsException(String message) {
this(message, 0, null, false);
}
/**
* Contructs a CmsException with the provided description and error code.
*
* @param s Exception message
* @param i Exception code
*/
public CmsException(String message, int type) {
this(message, type, null, false);
}
/**
* Construtcs a CmsException with a detail message and a forwarded
* root cause exception
*
* @param s Exception message
* @param e Forwarded root cause exception
*/
public CmsException(String message, Throwable rootCause) {
this(message, 0, rootCause, false);
}
/**
* Creates a CmsException with the provided error code,
* a forwarded root cause exception and a detail message.
*
* @param s Exception message
* @param i Exception code
* @param e Forwarded root cause exception
*/
public CmsException(String message, int type, Throwable rootCause) {
this(message, type, rootCause, false);
}
/**
* Creates a CmsException with a provided error code,
* a forwarded root cause exception and a detail message.
* The further processing of the exception can be controlled
* with the <code>useRoot</code> parameter.
*
* @param s Exception message
* @param i Exception code
* @param e Forwarded root cause exception
* @param useRoot If true, use
*/
public CmsException(String message, int type, Throwable rootCause, boolean useRoot) {
super(C_CMS_EXCEPTION_PREFIX + ": " + message);
this.m_message = message;
this.m_type = type;
this.m_rootCause = rootCause;
this.m_useRootCause = useRoot;
}
/**
* Get the root cause Exception which was provided
* when this exception was thrown.
*
* @return The root cause Exception.
*/
public Exception getException() {
if (m_useRootCause) return null;
try {
return (Exception)getRootCause();
} catch (ClassCastException e) {
return null;
}
}
/**
* Get the root cause Throwable which was provided
* when this exception was thrown.
*
* @return The root cause Throwable.
*/
public Throwable getRootCause() {
return m_rootCause;
}
/**
* Set the root cause Exception value.
*
* @param value The root cause Exception
*/
public void setException(Throwable value) {
m_rootCause = value;
}
/**
* Get the throwable.
*
* @return Exception.
*/
public Throwable getThrowable() {
return m_rootCause;
}
/**
* Get the exeption message
*
* @return Exception messge.
*/
public String getMessage() {
return C_CMS_EXCEPTION_PREFIX + ": " + m_message;
}
/**
* Get the exeption message
*
* @return Exception messge.
*/
public String getShortException() {
return C_CMS_EXCEPTION_PREFIX + ": " + getType() + " " + C_EXTXT[getType()]
+ ". Detailed Error: " + m_message + ".";
}
/**
* Return a string with the stacktrace. for this exception
* and for all encapsulated exceptions.
* Creation date: (10/23/00 %r)
* @return java.lang.String
*/
public String getStackTraceAsString() {
java.io.StringWriter sw = new java.io.StringWriter();
java.io.PrintWriter pw = new java.io.PrintWriter(sw);
if (m_useRootCause && (m_rootCause != null)) {
// use stack trace of root cause
m_rootCause.printStackTrace(pw);
} else {
// use stack trace of this eception and add the root case
super.printStackTrace(pw);
// if there are any encapsulated exceptions, write them also.
if(m_rootCause != null) {
StringWriter _sw = new StringWriter();
PrintWriter _pw = new PrintWriter(_sw);
_pw.println("-----------");
_pw.println("Root cause:");
m_rootCause.printStackTrace(_pw);
_pw.close();
try {
_sw.close();
}
catch(Exception exc) {
// ignore the exception
}
StringTokenizer st = new StringTokenizer(_sw.toString(), "\n");
while(st.hasMoreElements()) {
String s = ">" + (String)st.nextElement();
while ( (s != null) && (! "".equals(s)) && ((s.endsWith("\r") || s.endsWith("\n") || s.endsWith(">"))) ) {
s = s.substring(0, s.length()-1);
}
if ((s != null) && (! "".equals(s))) pw.println(s);
}
}
}
pw.close();
try {
sw.close();
} catch(Exception exc) {
// ignore the exception
}
return sw.toString();
}
/**
* Get the type of the CmsException.
*
* @return Type of CmsException
*/
public int getType() {
return m_type;
}
/**
* Gets the exception type as text.
*
* @return Exception type in a text-version.
*/
public String getTypeText() {
return C_CMS_EXCEPTION_PREFIX + ": " + getType() + " " + C_EXTXT[getType()];
}
/**
* Print the exception stack trace to System.out.
*/
public void printStackTrace() {
printStackTrace(System.out);
}
/**
* Prints this <code>Throwable</code> and its backtrace to the
* specified print stream.
*/
public void printStackTrace(java.io.PrintStream s) {
s.println(getStackTraceAsString());
}
/**
* Prints this <code>Throwable</code> and its backtrace to the specified
* print writer.
*/
public void printStackTrace(java.io.PrintWriter s) {
s.println(getStackTraceAsString());
}
/**
* Overwrites the standart toString method.
*/
public String toString() {
StringBuffer output = new StringBuffer();
output.append(C_CMS_EXCEPTION_PREFIX + ": ");
output.append(m_type + " ");
output.append(CmsException.C_EXTXT[m_type] + ". ");
if (m_message != null && (!"".equals(m_message))) {
output.append("Detailed error: ");
output.append(m_message + ". ");
}
if(m_rootCause != null) {
output.append("\nroot cause was ");
output.append(m_rootCause);
}
return output.toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -