Class WrappedException

java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
de.team33.patterns.exceptional.dione.WrappedException
All Implemented Interfaces:
Serializable

public class WrappedException extends RuntimeException
An unchecked exception dedicated to (temporarily) wrap checked exceptions.
See Also:
  • Constructor Details

    • WrappedException

      public WrappedException(String message, Throwable cause)
      Initializes a new instance with the given message and cause.
    • WrappedException

      public WrappedException(Throwable cause)
      Initializes a new instance with the given cause and its message.
  • Method Details

    • reThrowCauseIf

      public final <X extends Throwable> WrappedException reThrowCauseIf(Predicate<? super Throwable> condition, Function<? super Throwable,X> mapping) throws X
      Applies a given mapping to the cause of this exception if the given condition applies 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 - A Predicate that is used to check the cause of this exception for applicability.
      mapping - A Function that 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

      public final <X extends Throwable> WrappedException reThrowCauseAs(Class<X> xClass) throws X
      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 - The Class that 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.