public final class ExceptionUtil extends Object
Throwables.| Modifier and Type | Field and Description |
|---|---|
static char |
INNER_CLASS_SEPARATOR_CHAR
Inner class separator character:
'$' == 36. |
static String |
PACKAGE_SEPARATOR
The package separator String:
".". |
static char |
PACKAGE_SEPARATOR_CHAR
Package separator character:
'.' == 46. |
| Modifier and Type | Method and Description |
|---|---|
static Throwable |
getCause(Throwable throwable)
Introspects the
Throwable to obtain the cause. |
static String |
getShortClassName(Class clazz)
Gets the class name minus the package name from a
Class. |
static String |
getShortClassName(Object object,
String valueIfNull)
Gets the class name minus the package name for an
Object. |
static String |
getShortClassName(String className)
Gets the class name minus the package name from a String.
|
protected static String[] |
getStackFrames(Throwable throwable)
Captures the stack trace associated with the specified
Throwable object, decomposing it into a list of stack
frames. |
static String |
getStackTrace(Throwable throwable)
Gets the stack trace from a Throwable as a String.
|
static boolean |
isCascadingThrowable()
Checks if the Throwable class has a
getCause method. |
static boolean |
isCascadingThrowable(Throwable throwable)
Checks whether this
Throwable class can store a cause. |
static void |
printStackTrace(Throwable throwable)
Prints the stack trace of a throwable to the standard error stream.
|
static void |
printStackTrace(Throwable throwable,
PrintStream out)
Prints the stack trace of a throwable to the specified stream.
|
static void |
printStackTrace(Throwable throwable,
PrintWriter out)
Prints the stack trace of a throwable to the specified writer.
|
static void |
removeCommonFrames(List causeFrames,
List wrapperFrames)
Removes common frames from the cause trace given the two stack
traces.
|
protected static void |
trimStackFrames(List stacks)
Trims the stack frames.
|
public static final char PACKAGE_SEPARATOR_CHAR
'.' == 46.public static final String PACKAGE_SEPARATOR
".".public static final char INNER_CLASS_SEPARATOR_CHAR
'$' == 36.public static Throwable getCause(Throwable throwable)
Introspects the Throwable to obtain the cause.
The method searches for methods with specific names that return a
Throwable object. This will pick up most wrapping
exceptions, including those from JDK 1.4, and the domingo exceptions.
The default list searched for are:
getCause()getNextException()getTargetException()getException()getSourceException()getRootCause()getCausedByException()getNested()In the absence of any such method, the object is inspected for a
detail field assignable to a Throwable.
If none of the above is found, returns null.
throwable - the throwable to introspect for a cause, may be nullThrowable, null
if none found or null throwable inputpublic static boolean isCascadingThrowable()
Checks if the Throwable class has a getCause method.
This is true for JDK 1.4 and above.
public static boolean isCascadingThrowable(Throwable throwable)
Checks whether this Throwable class can store a cause.
This method does not check whether it actually does store a cause.
throwable - the Throwable to examine, may be nulltrue if cascading, otherwise falsepublic static void removeCommonFrames(List causeFrames, List wrapperFrames) throws IllegalArgumentException
Removes common frames from the cause trace given the two stack traces.
causeFrames - stack trace of a cause throwablewrapperFrames - stack trace of a wrapper throwableIllegalArgumentException - if either argument is nullpublic static String getStackTrace(Throwable throwable)
Gets the stack trace from a Throwable as a String.
The result of this method vary by JDK version as this method uses
Throwable.printStackTrace(java.io.PrintWriter). On JDK1.3 and
earlier, the cause exception will not be shown unless the specified
throwable alters printStackTrace.
throwable - the Throwable to be examinedprintStackTrace(PrintWriter) methodpublic static String getShortClassName(Object object, String valueIfNull)
Gets the class name minus the package name for an Object.
object - the class to get the short name for, may be nullvalueIfNull - the value to return if nullpublic static String getShortClassName(Class clazz)
Gets the class name minus the package name from a Class.
clazz - the class to get the short name for.public static String getShortClassName(String className)
Gets the class name minus the package name from a String.
The string passed in is assumed to be a class name - it is not checked.
className - the className to get the short name forpublic static void printStackTrace(Throwable throwable)
throwable - a cascading throwablepublic static void printStackTrace(Throwable throwable, PrintStream out)
throwable - a cascading throwableout - PrintStream to use for output.printStackTrace(Throwable, PrintWriter)public static void printStackTrace(Throwable throwable, PrintWriter out)
throwable - a cascading throwableout - PrintWriter to use for output.protected static String[] getStackFrames(Throwable throwable)
Throwable object, decomposing it into a list of stack
frames.throwable - The Throwable.protected static void trimStackFrames(List stacks)
stacks - The list containing String[] elementsCopyright © 2005–2020. All rights reserved.