org.sape.carbon.core.exception
Class ExceptionUtility

java.lang.Object
  |
  +--org.sape.carbon.core.exception.ExceptionUtility

public class ExceptionUtility
extends Object

A utility for printing out and dealing with exceptions in a useful way. This utility supports the getCause method of the Exception class under JDK 1.4, but uses reflective invocation to be backwards compatible with JDK 1.3.

Copyright 2002 Sapient

Since:
carbon 1.0
Version:
$Revision: 1.8 $($Author: dvoet $ / $Date: 2003/05/05 21:21:21 $)
Author:
Greg Hinkle, January 2002

Field Summary
private static Class[] GET_CAUSE_PARAMS
          The parameters to the getCause method
 
Constructor Summary
ExceptionUtility()
           
 
Method Summary
static String captureStackTrace(Throwable throwable)
          Returns the stack trace information in the form of a string.
static Throwable getNestedException(Throwable throwable)
          Gets the nested or causal exception for the supplied throwable.
static String printStackTracesToString(Throwable throwable)
          This method returns a string of the stack trace of an exception as well as the stack traces for all causal or previous exceptions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GET_CAUSE_PARAMS

private static final Class[] GET_CAUSE_PARAMS
The parameters to the getCause method

Constructor Detail

ExceptionUtility

public ExceptionUtility()
Method Detail

printStackTracesToString

public static String printStackTracesToString(Throwable throwable)
This method returns a string of the stack trace of an exception as well as the stack traces for all causal or previous exceptions.

Parameters:
throwable - the exception for which the trace should be returned
Returns:
a string listing of the exceptions stack traces

captureStackTrace

public static String captureStackTrace(Throwable throwable)
Returns the stack trace information in the form of a string. Wrapper for java.lang.Throwable.printStackTrace(Writer).

Parameters:
throwable - the throwable for which the trace should be captured
Returns:
a string listing of the stack trace for the supplied throwable

getNestedException

public static Throwable getNestedException(Throwable throwable)
Gets the nested or causal exception for the supplied throwable. This method supports InvocationTargetExceptions as well as the Carbon Core's Exceptionable interface. It also supports the newly standardized getCause method of the JDK 1.4's Exception class. This is done via reflection to maintain backwards compatibility with JDK 1.3.

Parameters:
throwable - the throwable for which the nested exception should be retrieved
Returns:
The exception nested in the given exception. Returns < code>null if the exception type is not supported, or if the input is null.


Copyright 1999-2003 Sapient Corporation. All Rights Reserved.