com.lc.util
Class Exceptions

java.lang.Object
  |
  +--com.lc.util.Exceptions

public final class Exceptions
extends java.lang.Object

Utility class for managing exceptions.

Version:
$Revision: 1.1.1.1 $ $Date: 2002/02/19 22:12:03 $
Author:
Laurent Caillette

Method Summary
static java.lang.String getStackTraceAsString(java.lang.Throwable throwable)
          Gets the stack trace into a String.
static java.lang.Throwable[] peel(java.lang.Throwable throwable)
          Peels nested Throwables.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getStackTraceAsString

public static java.lang.String getStackTraceAsString(java.lang.Throwable throwable)
Gets the stack trace into a String.
Parameters:
throwable - The one to get the stack trace from.
Returns:
The stack trace as it would appear in the console.

peel

public static java.lang.Throwable[] peel(java.lang.Throwable throwable)
Peels nested Throwables.

Instances of Throwables may be nested through several exception handlers, each one creating an exception around the one caught. When the topmost throwables implement interface CascadingThrowable, it's possible to access to the 1st Throwable which is the original cause, or does not implement CascadingThrowable.

For the following code :

try {
  try {
    try {
      Throwable rte = new RuntimeException() ;
      throw rte ;
    } catch( Throwable th1 ) {
      throw new MyEncloser1( th1 ) // MyEncloser implements IThowableEncloser
    }
  } catch( Throwable th2 ) {
    throw new MyEncloser2( th2 ) // MyEncloser implements IThowableEncloser
  }
} catch( Throwable th ) {
  Throwable[] throwables = Exceptions.peel( th ) ;
}
We'll get :
 throwables[ 0 ] == rte
 throwables[ 1 ] == th1
 throwables[ 2 ] == th2
Parameters:
throwable - Potentially a CascadingThrowable.
Returns:
An array where the 1st element is the potential cause, or an empty array if the throwable was null.