Class WrappedException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
de.team33.patterns.exceptional.dione.WrappedException
- All Implemented Interfaces:
Serializable
An unchecked exception dedicated to (temporarily) wrap checked exceptions.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionWrappedException(String message, Throwable cause) Initializes a new instance with the given message and cause.WrappedException(Throwable cause) Initializes a new instance with the given cause and itsmessage. -
Method Summary
Modifier and TypeMethodDescriptionfinal <X extends Throwable>
WrappedExceptionreThrowCauseAs(Class<X> xClass) Rethrows the cause of this exception if it matches the given exception type, otherwise this exception will be returned.final <X extends Throwable>
WrappedExceptionreThrowCauseIf(Predicate<? super Throwable> condition, Function<? super Throwable, X> mapping) Applies a givenmappingto the cause of this exception if the givenconditionapplies and throws the result, otherwise this exception will be returned.Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
WrappedException
Initializes a new instance with the given message and cause. -
WrappedException
Initializes a new instance with the given cause and itsmessage.
-
-
Method Details
-
reThrowCauseIf
public final <X extends Throwable> WrappedException reThrowCauseIf(Predicate<? super Throwable> condition, Function<? super Throwable, X> mapping) throws XApplies a givenmappingto the cause of this exception if the givenconditionapplies and throws the result, otherwise this exception will be returned.- Type Parameters:
X- The exception type that is intended as a result of the given mapping and that is thrown by this method, if applicable.- Parameters:
condition- APredicatethat is used to check the cause of this exception for applicability.mapping- AFunctionthat converts the cause of this exception to a specific type of exception to be thrown at that point.- Returns:
- this exception.
- Throws:
X- The mapped exception, if present.
-
reThrowCauseAs
Rethrows the cause of this exception if it matches the given exception type, otherwise this exception will be returned.- Type Parameters:
X- The type of exception that is expected and, if applicable, thrown by this method.- Parameters:
xClass- TheClassthat represents the type of exception that is expected.- Returns:
- this exception.
- Throws:
X- the cause of this exception, cast to the given type, if applicable.
-