org.codehaus.spice.salt.lang
Class ExceptionUtil

java.lang.Object
  extended byorg.codehaus.spice.salt.lang.ExceptionUtil

public final class ExceptionUtil
extends Object

This class makes it easy to manipulate data stored in exceptions.

Version:
$Revision: 1.1 $ $Date: 2003/12/02 02:15:04 $
Author:
Peter Donald

Field Summary
static String SEPARATOR
          Constant that used to separate causes when recursively printing exceptions.
 
Constructor Summary
ExceptionUtil()
           
 
Method Summary
static String[] captureStackTrace(Throwable throwable)
          Captures the stack trace associated with this exception.
static String[] captureStackTrace(Throwable throwable, String stopLine)
          Captures the stack trace associated with this exception.
static Throwable getCause(Throwable throwable)
          Utility method to get cause of exception.
static Throwable getRootCause(Throwable throwable)
          Utility method to get thr root cause of an exception.
static String prettyPrintStackTrace(Throwable throwable, String stopLine)
          Pretty print the stack trace.
static String printStackTrace(Throwable throwable)
          Generate string for specified exception and the cause of this exception (if any).
static String printStackTrace(Throwable throwable, boolean printCause)
          Generate string for specified exception and if printCause is true will print all exception that caused this exception (if any).
static String printStackTrace(Throwable throwable, int depth, boolean printCause)
          Generate exception string for specified exception with specified number of lines including causes if printCause is true.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SEPARATOR

public static final String SEPARATOR
Constant that used to separate causes when recursively printing exceptions. Matches JDK1.4s separator.

See Also:
Constant Field Values
Constructor Detail

ExceptionUtil

public ExceptionUtil()
Method Detail

printStackTrace

public static String printStackTrace(Throwable throwable)
Generate string for specified exception and the cause of this exception (if any).

Parameters:
throwable - a Throwable
Returns:
the stack trace as a String

printStackTrace

public static String printStackTrace(Throwable throwable,
                                     boolean printCause)
Generate string for specified exception and if printCause is true will print all exception that caused this exception (if any).

Parameters:
throwable - a Throwable
printCause - if true will print exceptions cause
Returns:
the stack trace as a String

printStackTrace

public static String printStackTrace(Throwable throwable,
                                     int depth,
                                     boolean printCause)
Generate exception string for specified exception with specified number of lines including causes if printCause is true.

Parameters:
throwable - a Throwable
depth - number of stack trace frames to show
printCause - if true will print the causes of all exceptions
Returns:
the stack trace as a String

prettyPrintStackTrace

public static String prettyPrintStackTrace(Throwable throwable,
                                           String stopLine)
Pretty print the stack trace. This involves printing out the message from each exception in chain and then printing the stack trace of the root cause up untile the stop line.

Parameters:
throwable - the exception
stopLine - the stop line

getRootCause

public static Throwable getRootCause(Throwable throwable)
Utility method to get thr root cause of an exception.

Parameters:
throwable - a Throwable
Returns:
cause of specified exception

getCause

public static Throwable getCause(Throwable throwable)
Utility method to get cause of exception.

Parameters:
throwable - a Throwable
Returns:
cause of specified exception

captureStackTrace

public static String[] captureStackTrace(Throwable throwable)
Captures the stack trace associated with this exception.

Parameters:
throwable - a Throwable
Returns:
an array of Strings describing stack frames.

captureStackTrace

public static String[] captureStackTrace(Throwable throwable,
                                         String stopLine)
Captures the stack trace associated with this exception. The stack trace terminates at any line containing the contents of "stopLine".

Parameters:
throwable - a Throwable
stopLine - the stopLine
Returns:
an array of Strings describing stack frames.


Copyright © 1999-2005 Codehaus. All Rights Reserved.