|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.codehaus.plexus.util.ExceptionUtils
public class ExceptionUtils
ExceptionUtils
provides utilities for manipulating
Throwable
objects.
Field Summary | |
---|---|
protected static java.lang.String[] |
CAUSE_METHOD_NAMES
The names of methods commonly used to access a wrapped exception. |
(package private) static java.lang.String |
WRAPPED_MARKER
Used when printing stack frames to denote the start of a wrapped exception. |
Constructor Summary | |
---|---|
protected |
ExceptionUtils()
Constructs a new ExceptionUtils . |
Method Summary | |
---|---|
static void |
addCauseMethodName(java.lang.String methodName)
Adds to the list of method names used in the search for Throwable
objects. |
static java.lang.Throwable |
getCause(java.lang.Throwable throwable)
Introspects the specified Throwable to obtain the cause. |
static java.lang.Throwable |
getCause(java.lang.Throwable throwable,
java.lang.String[] methodNames)
Introspects the specified Throwable to obtain the cause
using a supplied array of method names. |
private static java.lang.Throwable |
getCauseUsingFieldName(java.lang.Throwable throwable,
java.lang.String fieldName)
Find a throwable by field name. |
private static java.lang.Throwable |
getCauseUsingMethodName(java.lang.Throwable throwable,
java.lang.String methodName)
Find a throwable by method name. |
private static java.lang.Throwable |
getCauseUsingWellKnownTypes(java.lang.Throwable throwable)
Uses instanceof checks to examine the exception,
looking for well known types which could contain chained or
wrapped exceptions. |
static java.lang.String |
getFullStackTrace(java.lang.Throwable t)
A way to get the entire nested stack-trace of an throwable. |
static java.lang.Throwable |
getRootCause(java.lang.Throwable throwable)
Walks through the exception chain to the last element -- the "root" of the tree -- using getCause(Throwable) , and
returns that exception. |
static java.lang.String[] |
getRootCauseStackTrace(java.lang.Throwable t)
Creates a compact stack trace for the root cause of the supplied throwable. |
(package private) static java.util.List |
getStackFrameList(java.lang.Throwable t)
Produces a List of stack frames - the message is not included. |
(package private) static java.lang.String[] |
getStackFrames(java.lang.String stackTrace)
Functionality shared between the getStackFrames(Throwable) methods of this and the
classes. |
static java.lang.String[] |
getStackFrames(java.lang.Throwable t)
Captures the stack trace associated with the specified Throwable object, decomposing it into a list of
stack frames. |
static java.lang.String |
getStackTrace(java.lang.Throwable t)
A convenient way of extracting the stack trace from an exception. |
static int |
getThrowableCount(java.lang.Throwable throwable)
Returns the number of Throwable objects in the
exception chain. |
static java.lang.Throwable[] |
getThrowables(java.lang.Throwable throwable)
Returns the list of Throwable objects in the
exception chain. |
static int |
indexOfThrowable(java.lang.Throwable throwable,
java.lang.Class type)
Delegates to indexOfThrowable(Throwable, Class, int) ,
starting the search at the beginning of the exception chain. |
static int |
indexOfThrowable(java.lang.Throwable throwable,
java.lang.Class type,
int fromIndex)
Returns the (zero based) index, of the first Throwable that matches the specified type in the
exception chain of Throwable objects with an index
greater than or equal to the specified index, or
-1 if the type is not found. |
static boolean |
isNestedThrowable(java.lang.Throwable throwable)
Whether an Throwable is considered nested or not. |
static void |
printRootCauseStackTrace(java.lang.Throwable t)
Equivalent to printRootCauseStackTrace(t, System.err) |
static void |
printRootCauseStackTrace(java.lang.Throwable t,
java.io.PrintStream stream)
Prints a compact stack trace for the root cause of a throwable. |
static void |
printRootCauseStackTrace(java.lang.Throwable t,
java.io.PrintWriter writer)
Same as printRootCauseStackTrace(t, stream), except it takes a PrintWriter as an argument. |
private static void |
removeCommonFrames(java.util.List causeFrames,
java.util.List wrapperFrames)
Given two stack traces, removes common frames from the cause trace. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
static final java.lang.String WRAPPED_MARKER
protected static java.lang.String[] CAUSE_METHOD_NAMES
Constructor Detail |
---|
protected ExceptionUtils()
ExceptionUtils
. Protected to
discourage instantiation.
Method Detail |
---|
public static void addCauseMethodName(java.lang.String methodName)
Adds to the list of method names used in the search for Throwable
objects.
methodName
- the methodName to add to the list, null and empty strings are ignoredpublic static java.lang.Throwable getCause(java.lang.Throwable throwable)
Introspects the specified 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 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 exception to introspect for a cause.
Throwable
.
java.lang.NullPointerException
- if the throwable is nullpublic static java.lang.Throwable getCause(java.lang.Throwable throwable, java.lang.String[] methodNames)
Introspects the specified Throwable
to obtain the cause
using a supplied array of method names.
throwable
- The exception to introspect for a cause.
Throwable
.
java.lang.NullPointerException
- if the method names array is null or contains null
java.lang.NullPointerException
- if the throwable is nullpublic static java.lang.Throwable getRootCause(java.lang.Throwable throwable)
Walks through the exception chain to the last element -- the
"root" of the tree -- using getCause(Throwable)
, and
returns that exception.
throwable
- the throwable to get the root cause for
Throwable
.private static java.lang.Throwable getCauseUsingWellKnownTypes(java.lang.Throwable throwable)
Uses instanceof
checks to examine the exception,
looking for well known types which could contain chained or
wrapped exceptions.
throwable
- the exception to examine
null
if not
found.private static java.lang.Throwable getCauseUsingMethodName(java.lang.Throwable throwable, java.lang.String methodName)
Find a throwable by method name.
throwable
- the exception to examinemethodName
- the name of the method to find and invoke
null
if not
found.private static java.lang.Throwable getCauseUsingFieldName(java.lang.Throwable throwable, java.lang.String fieldName)
Find a throwable by field name.
throwable
- the exception to examinefieldName
- the name of the attribute to examine
null
if not
found.public static int getThrowableCount(java.lang.Throwable throwable)
Returns the number of Throwable
objects in the
exception chain.
throwable
- the exception to inspect
public static java.lang.Throwable[] getThrowables(java.lang.Throwable throwable)
Returns the list of Throwable
objects in the
exception chain.
throwable
- the exception to inspect
Throwable
objects.public static int indexOfThrowable(java.lang.Throwable throwable, java.lang.Class type)
Delegates to indexOfThrowable(Throwable, Class, int)
,
starting the search at the beginning of the exception chain.
indexOfThrowable(Throwable, Class, int)
public static int indexOfThrowable(java.lang.Throwable throwable, java.lang.Class type, int fromIndex)
Returns the (zero based) index, of the first
Throwable
that matches the specified type in the
exception chain of Throwable
objects with an index
greater than or equal to the specified index, or
-1
if the type is not found.
throwable
- the exception to inspecttype
- Class
to look forfromIndex
- the (zero based) index of the starting
position in the chain to be searched
-1
if the type is not found
java.lang.IndexOutOfBoundsException
- If the fromIndex
argument is negative or not less than the count of
Throwable
s in the chain.public static void printRootCauseStackTrace(java.lang.Throwable t, java.io.PrintStream stream)
The method is equivalent to t.printStackTrace() for throwables that don't have nested causes.
public static void printRootCauseStackTrace(java.lang.Throwable t)
public static void printRootCauseStackTrace(java.lang.Throwable t, java.io.PrintWriter writer)
public static java.lang.String[] getRootCauseStackTrace(java.lang.Throwable t)
printRootCauseStackTrace(Throwable t, PrintStream s)
private static void removeCommonFrames(java.util.List causeFrames, java.util.List wrapperFrames)
causeFrames
- stack trace of a cause throwablewrapperFrames
- stack trace of a wrapper throwablepublic static java.lang.String getStackTrace(java.lang.Throwable t)
t
- The Throwable
.
printStackTrace(PrintWriter)
method.public static java.lang.String getFullStackTrace(java.lang.Throwable t)
t
- The Throwable
.
public static boolean isNestedThrowable(java.lang.Throwable throwable)
throwable
- The Throwable
.
public static java.lang.String[] getStackFrames(java.lang.Throwable t)
Throwable
object, decomposing it into a list of
stack frames.
t
- The Throwable
.
static java.lang.String[] getStackFrames(java.lang.String stackTrace)
getStackFrames(Throwable)
methods of this and the
classes.
static java.util.List getStackFrameList(java.lang.Throwable t)
t
- is any throwable
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |