org.openorb.util
Class ExceptionTool

java.lang.Object
  |
  +--org.openorb.util.ExceptionTool

public final class ExceptionTool
extends Object

A utility class for optionaly attaching causal objects to exceptions if the exception implementation supports initCause. Note that these utilities only are safe to use in JDK 1.3 bu only have an effect under JDK 1.4+.

Version:
$Id: ExceptionTool.java,v 1.4 2004/02/10 21:28:45 mrumpf Exp $
Author:
Richard G Clark

Method Summary
static Throwable appendCause(Throwable e, Throwable cause)
          Attaches a Throwable to the end of the causal chain, if possible.
static Throwable appendPossibleCause(Throwable e, Throwable cause)
          Attaches a Throwable to the end of the causal chain as a possible cause, if possible.
static Throwable getCause(Throwable e)
          Returns the cause associated with the Throwable if available.
static Error initCause(Error e, Throwable cause)
          Attaches the cause to the exception if this operation is supported by the current environment.
static RuntimeException initCause(RuntimeException e, Throwable cause)
          Attaches the cause to the exception if this operation is supported by the current environment.
static SystemException initCause(SystemException e, Throwable cause)
          Attaches the cause to the exception if this operation is supported by the current environment.
static Throwable initCause(Throwable e, Throwable cause)
          Attaches the cause to the exception if this operation is supported by the current environment.
static UserException initCause(UserException e, Throwable cause)
          Attaches the cause to the exception if this operation is supported by the current environment.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getCause

public static Throwable getCause(Throwable e)
Returns the cause associated with the Throwable if available.
Parameters:
e - the Throwable to get the cause from
Returns:
the cause if available, null if not

initCause

public static SystemException initCause(SystemException e,
                                        Throwable cause)
Attaches the cause to the exception if this operation is supported by the current environment.
Parameters:
e - the exception to attach the cause to
cause - the cause of this specified exception
Returns:
the parameter e

initCause

public static UserException initCause(UserException e,
                                      Throwable cause)
Attaches the cause to the exception if this operation is supported by the current environment.
Parameters:
e - the exception to attach the cause to
cause - the cause of this specified exception
Returns:
the parameter e

initCause

public static Throwable initCause(Throwable e,
                                  Throwable cause)
Attaches the cause to the exception if this operation is supported by the current environment.
Parameters:
e - the exception to attach the cause to
cause - the cause of this specified exception
Returns:
the parameter e

initCause

public static RuntimeException initCause(RuntimeException e,
                                         Throwable cause)
Attaches the cause to the exception if this operation is supported by the current environment.
Parameters:
e - the exception to attach the cause to
cause - the cause of this specified exception
Returns:
the parameter e

initCause

public static Error initCause(Error e,
                              Throwable cause)
Attaches the cause to the exception if this operation is supported by the current environment.
Parameters:
e - the exception to attach the cause to
cause - the cause of this specified exception
Returns:
the parameter e

appendCause

public static Throwable appendCause(Throwable e,
                                    Throwable cause)
Attaches a Throwable to the end of the causal chain, if possible. If the cause of the last Throwable is explicity set to null then attachment is not possible.
Parameters:
e - the recipient of the attachment
cause - the attachment
Returns:
the recipient
Throws:
NullPointerException - if e is null
IllegalArgumentException - if e == cause

appendPossibleCause

public static Throwable appendPossibleCause(Throwable e,
                                            Throwable cause)
Attaches a Throwable to the end of the causal chain as a possible cause, if possible. If the cause of the last Throwable is explicity set to null then attachment is not possible. This utility would be used to retain the possible root cause of a problem that can be masked by an exception thrown in the finally block. For Example:
     final Throwable cause = null;
     try {
         someMethod();
     } catch (final Exception e) {
         possibleCause = e;
         throw e;
     } finally {
        try {
            cleanUp();
        } catch (final Exception e2) {
            ExceptionTool.appendPossibleCause(e2, e);
            throw e2;
        }
     }
 
Parameters:
e - the recipient of the attachment
cause - the attachment
Returns:
the recipient
Throws:
NullPointerException - if e is null
IllegalArgumentException - if e == cause