de.bea.domingo.exception
Class ExceptionUtil

java.lang.Object
  extended by de.bea.domingo.exception.ExceptionUtil

public final class ExceptionUtil
extends java.lang.Object

Utilities for manipulating and examining Throwables.


Field Summary
static char INNER_CLASS_SEPARATOR_CHAR
          Inner class separator character: '$' == 36.
static java.lang.String PACKAGE_SEPARATOR
          The package separator String: ".".
static char PACKAGE_SEPARATOR_CHAR
          Package separator character: '.' == 46.
 
Method Summary
static java.lang.Throwable getCause(java.lang.Throwable throwable)
          Introspects the Throwable to obtain the cause.
static java.lang.String getShortClassName(java.lang.Class clazz)
          Gets the class name minus the package name from a Class.
static java.lang.String getShortClassName(java.lang.Object object, java.lang.String valueIfNull)
          Gets the class name minus the package name for an Object.
static java.lang.String getShortClassName(java.lang.String className)
          Gets the class name minus the package name from a String.
(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)
          Returns an array where each element is a line from the argument.
protected static java.lang.String[] getStackFrames(java.lang.Throwable throwable)
          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 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(java.lang.Throwable throwable)
          Checks whether this Throwable class can store a cause.
static void printStackTrace(java.lang.Throwable throwable)
          Prints the stack trace of a throwable to the standard error stream.
static void printStackTrace(java.lang.Throwable throwable, java.io.PrintStream out)
          Prints the stack trace of a throwable to the specified stream.
static void printStackTrace(java.lang.Throwable throwable, java.io.PrintWriter out)
          Prints the stack trace of a throwable to the specified writer.
static void removeCommonFrames(java.util.List causeFrames, java.util.List wrapperFrames)
          Removes common frames from the cause trace given the two stack traces.
protected static void trimStackFrames(java.util.List stacks)
          Trims the stack frames.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PACKAGE_SEPARATOR_CHAR

public static final char PACKAGE_SEPARATOR_CHAR
Package separator character: '.' == 46.

See Also:
Constant Field Values

PACKAGE_SEPARATOR

public static final java.lang.String PACKAGE_SEPARATOR
The package separator String: ".".


INNER_CLASS_SEPARATOR_CHAR

public static final char INNER_CLASS_SEPARATOR_CHAR
Inner class separator character: '$' == 36.

See Also:
Constant Field Values
Method Detail

getCause

public static java.lang.Throwable getCause(java.lang.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:

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.

Parameters:
throwable - the throwable to introspect for a cause, may be null
Returns:
the cause of the Throwable, null if none found or null throwable input

isCascadingThrowable

public static boolean isCascadingThrowable()

Checks if the Throwable class has a getCause method.

This is true for JDK 1.4 and above.

Returns:
true if Throwable is cascading

isCascadingThrowable

public static boolean isCascadingThrowable(java.lang.Throwable throwable)

Checks whether this Throwable class can store a cause.

This method does not check whether it actually does store a cause.

Parameters:
throwable - the Throwable to examine, may be null
Returns:
boolean true if cascading, otherwise false

removeCommonFrames

public static void removeCommonFrames(java.util.List causeFrames,
                                      java.util.List wrapperFrames)
                               throws java.lang.IllegalArgumentException

Removes common frames from the cause trace given the two stack traces.

Parameters:
causeFrames - stack trace of a cause throwable
wrapperFrames - stack trace of a wrapper throwable
Throws:
java.lang.IllegalArgumentException - if either argument is null

getStackTrace

public static java.lang.String getStackTrace(java.lang.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.

Parameters:
throwable - the Throwable to be examined
Returns:
the stack trace as generated by the exception's printStackTrace(PrintWriter) method

getStackFrames

static java.lang.String[] getStackFrames(java.lang.String stackTrace)

Returns an array where each element is a line from the argument.

The end of line is determined by the value of line.separator system property.

Parameters:
stackTrace - a stack trace String
Returns:
an array where each element is a line from the argument

getStackFrameList

static java.util.List getStackFrameList(java.lang.Throwable t)

Produces a List of stack frames - the message is not included. Only the trace of the specified exception is returned, any caused by trace is stripped.

This works in most cases - it will only fail if the exception message contains a line that starts with: "   at".

Parameters:
t - is any throwable
Returns:
List of stack frames

getShortClassName

public static java.lang.String getShortClassName(java.lang.Object object,
                                                 java.lang.String valueIfNull)

Gets the class name minus the package name for an Object.

Parameters:
object - the class to get the short name for, may be null
valueIfNull - the value to return if null
Returns:
the class name of the object without the package name, or the null value

getShortClassName

public static java.lang.String getShortClassName(java.lang.Class clazz)

Gets the class name minus the package name from a Class.

Parameters:
clazz - the class to get the short name for.
Returns:
the class name without the package name or an empty string

getShortClassName

public static java.lang.String getShortClassName(java.lang.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.

Parameters:
className - the className to get the short name for
Returns:
the class name of the class without the package name or an empty string

printStackTrace

public static void printStackTrace(java.lang.Throwable throwable)
Prints the stack trace of a throwable to the standard error stream.

Parameters:
throwable - a cascading throwable

printStackTrace

public static void printStackTrace(java.lang.Throwable throwable,
                                   java.io.PrintStream out)
Prints the stack trace of a throwable to the specified stream.

Parameters:
throwable - a cascading throwable
out - PrintStream to use for output.
See Also:
printStackTrace(Throwable, PrintWriter)

printStackTrace

public static void printStackTrace(java.lang.Throwable throwable,
                                   java.io.PrintWriter out)
Prints the stack trace of a throwable to the specified writer.

Parameters:
throwable - a cascading throwable
out - PrintWriter to use for output.

getStackFrames

protected static java.lang.String[] getStackFrames(java.lang.Throwable throwable)
Captures the stack trace associated with the specified Throwable object, decomposing it into a list of stack frames.

Parameters:
throwable - The Throwable.
Returns:
An array of strings describing each stack frame.

trimStackFrames

protected static void trimStackFrames(java.util.List stacks)
Trims the stack frames. The first set is left untouched. The rest of the frames are truncated from the bottom by comparing with one just on top.

Parameters:
stacks - The list containing String[] elements


Domingo Java-API