org.omnifaces.util
Class Exceptions

java.lang.Object
  extended by org.omnifaces.util.Exceptions

public final class Exceptions
extends java.lang.Object

Collection of general utility methods with respect to working with exceptions.

Author:
Bauke Scholtz

Method Summary
static
<T extends java.lang.Throwable>
boolean
is(java.lang.Throwable exception, java.lang.Class<T> type)
          Returns true if the given exception or one of its nested causes is an instance of the given type.
static
<T extends java.lang.Throwable>
java.lang.Throwable
unwrap(java.lang.Throwable exception)
          Unwrap the nested causes of given exception as long as until it is not an instance of FacesException (Mojarra) or ELException (MyFaces) and then return it.
static
<T extends java.lang.Throwable>
java.lang.Throwable
unwrap(java.lang.Throwable exception, java.lang.Class<T> type)
          Unwrap the nested causes of given exception as long as until it is not an instance of the given type and then return it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

unwrap

public static <T extends java.lang.Throwable> java.lang.Throwable unwrap(java.lang.Throwable exception,
                                                                         java.lang.Class<T> type)
Unwrap the nested causes of given exception as long as until it is not an instance of the given type and then return it. If the given exception is already not an instance of the given type, then it will directly be returned. Or if the exception, unwrapped or not, does not have a nested cause anymore, then it will be returned. This is particularly useful if you want to unwrap the real root cause out of a nested hierarchy of ServletException or FacesException.

Parameters:
exception - The exception to be unwrapped.
type - The type which needs to be unwrapped.
Returns:
The unwrapped root cause.

unwrap

public static <T extends java.lang.Throwable> java.lang.Throwable unwrap(java.lang.Throwable exception)
Unwrap the nested causes of given exception as long as until it is not an instance of FacesException (Mojarra) or ELException (MyFaces) and then return it. If the given exception is already not an instance of the mentioned types, then it will directly be returned. Or if the exception, unwrapped or not, does not have a nested cause anymore, then it will be returned.

Parameters:
exception - The exception to be unwrapped from FacesException and ELException.
Returns:
The unwrapped root cause.
Since:
1.4

is

public static <T extends java.lang.Throwable> boolean is(java.lang.Throwable exception,
                                                         java.lang.Class<T> type)
Returns true if the given exception or one of its nested causes is an instance of the given type.

Parameters:
exception - The exception to be checked.
type - The type to be compared to.
Returns:
true if the given exception or one of its nested causes is an instance of the given type.