Top Description Fields Constructors Methods
org.apache.avalon.framework

public final Class ExceptionUtil

extends Object
Class Inheritance
Imports
java.io.PrintWriter, .StringWriter, java.lang.reflect.Method, java.util.StringTokenizer

This class provides basic facilities for manipulating exceptions. Some exception handling stuff thieved from Turbine...
Author
Avalon Development Team

Field Summary

Modifier and TypeField and Description
private static final String
private static final Class<T>[]
private static final String

Constructor Summary

AccessConstructor and Description
private
ExceptionUtil()

Private constructor to prevent instantiation.

Method Summary

Modifier and TypeMethod and Description
public static String[]

Returns:

an array of Strings describing stack frames.
captureStackTrace
(final Throwable
a Throwable
throwable
)

Captures the stack trace associated with this exception.

public static Throwable

Returns:

cause of specified exception
getCause
(final Throwable
a Throwable
throwable
,
final boolean
if true will use reflection to handle JDK1.4 nested exceptions
useReflection
)

Utility method to get cause of exception.

public static String

Returns:

the stack trace as a String
printStackTrace
(final Throwable
a Throwable
throwable
)

Generate string for specified exception and the cause of this exception (if any).

public static String

Returns:

the stack trace as a String
printStackTrace
(final Throwable
a Throwable
throwable
,
final boolean
if true will print all cascading exceptions
printCascading
)

Generate string for specified exception and if printCascading is true will print all cascading exceptions.

public static String

Returns:

the stack trace as a String
printStackTrace
(final Throwable
a Throwable
throwable
,
final int
number of stack trace frames to show
depth
)

Serialize the specified Throwable to a string.

public static String

Returns:

the stack trace as a String
printStackTrace
(final Throwable
a Throwable
throwable
,
final int
number of stack trace frames to show
depth
,
final boolean
if true will print all cascading exceptions
printCascading
)

Generate exception string for specified exception to specified depth and all Cascading exceptions if printCascading is true.

public static String

Returns:

the stack trace as a String
printStackTrace
(final Throwable
a Throwable
throwable
,
final int
number of stack trace frames to show
depth
,
final boolean
if true will print all cascading exceptions
printCascading
,
final boolean
if true will use reflection to handle JDK1.4 nested exceptions
useReflection
)

Generate exception string for specified exception to specified depth and all Cascading exceptions if printCascading is true.

public static String[]

Returns:

the resultant array
splitString
(final String
the string to split
string
,
final String
the token to split on
onToken
)

Deprecated This is an internal utility method that should not be used
Splits the string on every token into an array of stack frames.
private static String[]

Returns:

the resultant array
splitStringInternal
(final String
the string to split
string
,
final String
the token to split on
onToken
)

Splits the string on every token into an array of stack frames.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

GET_CAUSE_NAMEback to summary
private static final String GET_CAUSE_NAME
GET_CAUSE_PARAMTYPESback to summary
private static final Class<T>[] GET_CAUSE_PARAMTYPES
LINE_SEPARATORback to summary
private static final String LINE_SEPARATOR

Constructor Detail

ExceptionUtilback to summary
private ExceptionUtil()

Private constructor to prevent instantiation.

Method Detail

captureStackTraceback to summary
public static String[] captureStackTrace(final Throwable throwable)

Captures the stack trace associated with this exception.

Parameters
throwable:Throwable

a Throwable

Returns:String[]

an array of Strings describing stack frames.

getCauseback to summary
public static Throwable getCause(final Throwable throwable, final boolean useReflection)

Utility method to get cause of exception.

Parameters
throwable:Throwable

a Throwable

useReflection:boolean

if true will use reflection to handle JDK1.4 nested exceptions

Returns:Throwable

cause of specified exception

printStackTraceback to summary
public static String printStackTrace(final Throwable throwable)

Generate string for specified exception and the cause of this exception (if any).

Parameters
throwable:Throwable

a Throwable

Returns:String

the stack trace as a String

printStackTraceback to summary
public static String printStackTrace(final Throwable throwable, final boolean printCascading)

Generate string for specified exception and if printCascading is true will print all cascading exceptions.

Parameters
throwable:Throwable

a Throwable

printCascading:boolean

if true will print all cascading exceptions

Returns:String

the stack trace as a String

printStackTraceback to summary
public static String printStackTrace(final Throwable throwable, final int depth)

Serialize the specified Throwable to a string. Restrict the number of frames printed out to the specified depth. If the depth specified is 0 then all the frames are converted into a string.

Parameters
throwable:Throwable

a Throwable

depth:int

number of stack trace frames to show

Returns:String

the stack trace as a String

printStackTraceback to summary
public static String printStackTrace(final Throwable throwable, final int depth, final boolean printCascading)

Generate exception string for specified exception to specified depth and all Cascading exceptions if printCascading is true.

Parameters
throwable:Throwable

a Throwable

depth:int

number of stack trace frames to show

printCascading:boolean

if true will print all cascading exceptions

Returns:String

the stack trace as a String

printStackTraceback to summary
public static String printStackTrace(final Throwable throwable, final int depth, final boolean printCascading, final boolean useReflection)

Generate exception string for specified exception to specified depth and all Cascading exceptions if printCascading is true. If useReflection is true then the method will also attempt to use reflection to find a method with signature Throwable getCause(). This makes it compatible with JDK1.4 mechanisms for nesting exceptions.

Parameters
throwable:Throwable

a Throwable

depth:int

number of stack trace frames to show

printCascading:boolean

if true will print all cascading exceptions

useReflection:boolean

if true will use reflection to handle JDK1.4 nested exceptions

Returns:String

the stack trace as a String

splitStringback to summary
public static String[] splitString(final String string, final String onToken)

Deprecated

This is an internal utility method that should not be used

Splits the string on every token into an array of stack frames.

Parameters
string:String

the string to split

onToken:String

the token to split on

Returns:String[]

the resultant array

splitStringInternalback to summary
private static String[] splitStringInternal(final String string, final String onToken)

Splits the string on every token into an array of stack frames.

Parameters
string:String

the string to split

onToken:String

the token to split on

Returns:String[]

the resultant array