org.topbraid.base.util
Class ExceptionUtil

java.lang.Object
  extended by org.topbraid.base.util.ExceptionUtil

public class ExceptionUtil
extends Object

A collection of utilities on Exception handling.


Constructor Summary
ExceptionUtil()
           
 
Method Summary
static
<EX extends Throwable>
EX
throwDeepCauseChecked(Throwable t, Class<? extends EX> clazz)
          Always throw an exception; based on t.
static RuntimeException throwRootCauseUnchecked(Throwable t)
          Does not return: throws an unchecked exception, based on t.
static RuntimeException throwUnchecked(Throwable t)
          Does not return: throws an unchecked exception, based on t.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExceptionUtil

public ExceptionUtil()
Method Detail

throwRootCauseUnchecked

public static RuntimeException throwRootCauseUnchecked(Throwable t)
Does not return: throws an unchecked exception, based on t. First, the getCause chain of t is followed to its base, and then, an appropriate throwable exception is thrown, with preference to throwing an Error.

Parameters:
t - The underlying problem.
Throws:
Error - If there is an underlying Error
RuntimeException - Otherwise

throwUnchecked

public static RuntimeException throwUnchecked(Throwable t)
Does not return: throws an unchecked exception, based on t. If t can be thrown directly, it is, otherwise it is wrapped as a RuntimeException.

Parameters:
t - The underlying problem.
Returns:
Never returns, return type is for idiom "throw throwUnchecked();" to clarify that next line is not reached.
Throws:
Error - If t is an Error
RuntimeException - Otherwise

throwDeepCauseChecked

public static <EX extends Throwable> EX throwDeepCauseChecked(Throwable t,
                                                              Class<? extends EX> clazz)
                                                  throws EX extends Throwable
Always throw an exception; based on t. The getCause chain of t is analyzed, and then, an appropriate Throwable is thrown, with preference as follows:
  1. An Error.
  2. An exception that is of type clazz (or a subtype).
  3. A runtime exception.
  4. A new Exception of type clazz that has cause t
If one of the first three is thrown, then it is the first one of that type in the causal chain.

Type Parameters:
Ex - The type of exception thrown by the constructor of V
Parameters:
t - The underlying problem.
clazz - The class of exception to look for. This clazz must not be abstract and must have either a no element constructor or a constructor with one argument being a throwable.
Throws:
Error - If there is an underlying Error
RuntimeException - If there is an underlying RuntimeException and no exception of type EX
EX - If there is an appropriate exception or otherwise
IllegalArgumentException - If clazz is inappropriate (not always checked).
EX extends Throwable


Copyright © 2011 TopQuadrant, Inc.. All Rights Reserved.