public class ExceptionUtils extends Object
Provides utilities for manipulating and examining
Throwable objects.
| Constructor and Description |
|---|
ExceptionUtils()
Public constructor allows an instance of
ExceptionUtils to be created, although that is not
normally necessary. |
| Modifier and Type | Method and Description |
|---|---|
static Throwable |
getCause(Throwable throwable)
Introspects the
Throwable to obtain the cause. |
static Throwable |
getCause(Throwable throwable,
String[] methodNames)
Introspects the
Throwable to obtain the cause. |
static String |
getFullStackTrace(Throwable throwable)
A way to get the entire nested stack-trace of an throwable.
|
static List |
getThrowableList(Throwable throwable)
Returns the list of
Throwable objects in the
exception chain. |
static Throwable[] |
getThrowables(Throwable throwable)
Returns the list of
Throwable objects in the
exception chain. |
static boolean |
isNestedThrowable(Throwable throwable)
Checks whether this
Throwable class can store a cause. |
static boolean |
isThrowableNested()
Checks if the Throwable class has a
getCause method. |
public ExceptionUtils()
Public constructor allows an instance of ExceptionUtils to be created, although that is not
normally necessary.
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
NestableException.
The method names can be added to using #addCauseMethodName(String).
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 Throwable getCause(Throwable throwable, String[] methodNames)
Introspects the Throwable to obtain the cause.
A null set of method names means use the default set.
A null in the set of method names will be ignored.
throwable - the throwable to introspect for a cause, may be nullmethodNames - the method names, null treated as default setThrowable,
null if none found or null throwable inputpublic static boolean isThrowableNested()
Checks if the Throwable class has a getCause method.
This is true for JDK 1.4 and above.
public static boolean isNestedThrowable(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 nested otherwise falsepublic static Throwable[] getThrowables(Throwable throwable)
Returns the list of Throwable objects in the
exception chain.
A throwable without cause will return an array containing
one element - the input throwable.
A throwable with one cause will return an array containing
two elements. - the input throwable and the cause throwable.
A null throwable will return an array of size zero.
From version 2.2, this method handles recursive cause structures that might otherwise cause infinite loops. The cause chain is processed until the end is reached, or until the next item in the chain is already in the result set.
throwable - the throwable to inspect, may be nullgetThrowableList(Throwable)public static List getThrowableList(Throwable throwable)
Returns the list of Throwable objects in the
exception chain.
A throwable without cause will return a list containing
one element - the input throwable.
A throwable with one cause will return a list containing
two elements. - the input throwable and the cause throwable.
A null throwable will return a list of size zero.
This method handles recursive cause structures that might otherwise cause infinite loops. The cause chain is processed until the end is reached, or until the next item in the chain is already in the result set.
throwable - the throwable to inspect, may be nullpublic static String getFullStackTrace(Throwable throwable)
A way to get the entire nested stack-trace of an throwable.
The result of this method is highly dependent on the JDK version and whether the exceptions override printStackTrace or not.
throwable - the Throwable to be examinedCopyright © 2010–2014 The Apache Software Foundation. All rights reserved.