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 Throwable |
unwrap(Throwable exception,
Class<? extends Throwable>... types)
Unwrap the nested causes of given exception as long as until it is not an instance of the given types and then
return it.
|
@SafeVarargs public static Throwable unwrap(Throwable exception, Class<? extends Throwable>... types)
ServletException
or FacesException
.exception
- The exception to be unwrapped.types
- The types which need 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–2016 OmniFaces. All rights reserved.