Class ExceptionUtils.WrappedException

java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
dev.metaschema.core.util.ExceptionUtils.WrappedException
All Implemented Interfaces:
Serializable
Enclosing class:
ExceptionUtils

public static final class ExceptionUtils.WrappedException extends RuntimeException
A runtime exception that wraps a checked exception, allowing it to be thrown from contexts that do not allow checked exceptions (such as lambda expressions).
See Also:
  • Constructor Details

    • WrappedException

      public WrappedException(@NonNull Throwable cause)
      Construct a new wrapped exception.
      Parameters:
      cause - the exception to wrap
  • Method Details

    • initCause

      public Throwable initCause(Throwable cause)
      Overrides:
      initCause in class Throwable
    • unwrap

      @NonNull public Throwable unwrap()
      Get the wrapped exception.
      Returns:
      the original exception that was wrapped
    • unwrap

      @NonNull public <E extends Throwable> E unwrap(@NonNull Class<E> wrappedExceptionClass)
      Get the wrapped exception, casting it to the expected type.
      Type Parameters:
      E - the expected exception type
      Parameters:
      wrappedExceptionClass - the class of the expected exception type
      Returns:
      the original exception cast to the expected type
      Throws:
      IllegalArgumentException - if the wrapped exception is not of the expected type
    • unwrapAndThrow

      public void unwrapAndThrow() throws Throwable
      Unwrap and throw the original exception.
      Throws:
      Throwable - the original wrapped exception
    • unwrapAndThrow

      public <E extends Throwable> void unwrapAndThrow(@NonNull Class<E> wrappedExceptionClass) throws E
      Unwrap and throw the original exception, cast to the expected type.
      Type Parameters:
      E - the expected exception type
      Parameters:
      wrappedExceptionClass - the class of the expected exception type
      Throws:
      E - the original wrapped exception cast to the expected type