|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.commons.lang.exception.ExceptionUtils
Utility routines for manipulating Throwable
objects.
Field Summary | |
protected static String[] |
CAUSE_METHOD_NAMES
The names of methods commonly used to access a wrapped exception. |
protected static Object[] |
CAUSE_METHOD_PARAMS
The empty parameter list passed to methods used to access a wrapped exception. |
Constructor Summary | |
protected |
ExceptionUtils()
Constructs a new ExceptionUtils . |
Method Summary | |
static Throwable |
getCause(Throwable t)
Introspects the specified Throwable for a
getCause() , getNextException() ,
getTargetException() , or
getException() method which returns a
Throwable object (standard as of JDK 1.4, and part
of the NestableException API),
extracting and returning the cause of the exception. |
static Throwable |
getCause(Throwable t,
String[] methodNames)
Extends the API of getCause(Throwable) by
introspecting for only user-specified method names. |
private static Throwable |
getCauseUsingFieldName(Throwable t,
String fieldName)
|
private static Throwable |
getCauseUsingMethodName(Throwable t,
String methodName)
|
private static Throwable |
getCauseUsingWellKnownTypes(Throwable t)
Uses instanceof checks to examine the exception,
looking for well known types which could contain chained or
wrapped exceptions. |
static Throwable |
getRootCause(Throwable t)
Walks through the exception chain to the last element -- the "root" of the tree -- using getCause(Throwable) , and
returns that exception. |
(package private) static String[] |
getStackFrames(String stackTrace)
Functionality shared between the getStackFrames(Throwable) methods of this and the
NestableDelegate
classes. |
static String[] |
getStackFrames(Throwable t)
Captures the stack trace associated with the specified Throwable object, decomposing it into a list of
stack frames. |
static String |
getStackTrace(Throwable t)
A convenient way of extracting the stack trace from an exception. |
static int |
getThrowableCount(Throwable t)
Returns the number of Throwable objects in the
exception chain. |
static Throwable[] |
getThrowables(Throwable t)
Returns the list of Throwable objects in the
exception chain. |
static int |
indexOfThrowable(Throwable t,
Class type)
Delegates to indexOfThrowable(Throwable, Class, int) ,
starting the search at the beginning of the exception chain. |
static int |
indexOfThrowable(Throwable t,
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. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected static final String[] CAUSE_METHOD_NAMES
protected static final Object[] CAUSE_METHOD_PARAMS
Constructor Detail |
protected ExceptionUtils()
ExceptionUtils
. Protected to
discourage instantiation.
Method Detail |
public static Throwable getCause(Throwable t)
Throwable
for a
getCause()
, getNextException()
,
getTargetException()
, or
getException()
method which returns a
Throwable
object (standard as of JDK 1.4, and part
of the NestableException
API),
extracting and returning the cause of the exception. 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
.
t
- The exception to introspect for a cause.
Throwable
.public static Throwable getCause(Throwable t, String[] methodNames)
getCause(Throwable)
by
introspecting for only user-specified method names.
getCause(Throwable)
public static Throwable getRootCause(Throwable t)
getCause(Throwable)
, and
returns that exception.
Throwable
.getCause(Throwable)
private static Throwable getCauseUsingWellKnownTypes(Throwable t)
instanceof
checks to examine the exception,
looking for well known types which could contain chained or
wrapped exceptions.
t
- The exception to examine.
null
if not
found.private static Throwable getCauseUsingMethodName(Throwable t, String methodName)
t
- The exception to examine.methodName
- The name of the method to find and invoke.
null
if not
found.private static Throwable getCauseUsingFieldName(Throwable t, String fieldName)
t
- The exception to examine.fieldName
- The name of the attribute to examine.
null
if not
found.public static int getThrowableCount(Throwable t)
Throwable
objects in the
exception chain.
t
- The exception to inspect.
public static Throwable[] getThrowables(Throwable t)
Throwable
objects in the
exception chain.
t
- The exception to inspect.
Throwable
objects.public static int indexOfThrowable(Throwable t, Class type)
indexOfThrowable(Throwable, Class, int)
,
starting the search at the beginning of the exception chain.
indexOfThrowable(Throwable, Class, int)
public static int indexOfThrowable(Throwable t, Class type, int fromIndex)
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.
t
- The exception to inspect.type
- Class
to look for.fromIndex
- The (zero based) index of the starting
position in the chain to be searched.
-1
if the type is not found.
IndexOutOfBoundsException
- If the fromIndex
argument is negative or not less than the count of
Throwable
s in the chain.public static String getStackTrace(Throwable t)
t
- The Throwable
.
printStackTrace(PrintWriter)
method.public static String[] getStackFrames(Throwable t)
Throwable
object, decomposing it into a list of
stack frames.
t
- The Throwable
.
static String[] getStackFrames(String stackTrace)
getStackFrames(Throwable)
methods of this and the
NestableDelegate
classes.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |