public final class Exceptions extends Object
Collection of general utility methods with respect to working with exceptions. So far there's only an unwrapper and a type checker.
Some examples:
// Check if the caught exception has a ConstraintViolationException in its hierarchy. catch (PersistenceException e) { if (Exceptions.is(e, ConstraintViolationException.class)) { // ... } }
// Unwrap the caught FacesException until a non-FacesException is found. catch (FacesException e) { Exception realRootCause = Exceptions.unwrap(e, FacesException.class); // ... }
Modifier and Type | Method and Description |
---|---|
static <T extends Throwable> |
is(Throwable exception,
Class<T> type)
Returns
true if the given exception or one of its nested causes is an instance of the given type. |
static Throwable |
unwrap(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 Throwable> |
unwrap(Throwable exception,
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.
|
public static <T extends Throwable> Throwable unwrap(Throwable exception, Class<T> type)
ServletException
or FacesException
.T
- The generic throwable type.exception
- The exception to be unwrapped.type
- The type which needs to be unwrapped.public static Throwable unwrap(Throwable exception)
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.exception
- The exception to be unwrapped from FacesException
and ELException
.public static <T extends Throwable> boolean is(Throwable exception, Class<T> type)
true
if the given exception or one of its nested causes is an instance of the given type.T
- The generic throwable type.exception
- The exception to be checked.type
- The type to be compared to.true
if the given exception or one of its nested causes is an instance of the given type.Copyright © 2012–2015 OmniFaces. All rights reserved.