Class ExceptionUtils

java.lang.Object
dev.metaschema.core.util.ExceptionUtils

public final class ExceptionUtils extends Object
Provides a means for throwing important checked exceptions over non-checked methods, e.g. lambda invocations.

This capability should be used with care, and generally in limited circumstances.

  • Method Details

    • wrap

      @NonNull public static ExceptionUtils.WrappedException wrap(@NonNull Throwable ex)
      Wrap a checked exception in an unchecked ExceptionUtils.WrappedException.
      Parameters:
      ex - the exception to wrap
      Returns:
      a new wrapped exception containing the provided exception
    • wrapAndThrow

      @NonNull public static ExceptionUtils.WrappedException wrapAndThrow(@NonNull Throwable ex)
      Wrap a checked exception in an unchecked ExceptionUtils.WrappedException.

      This method is identical to wrap(Throwable) but named to indicate intent when used in throw statements.

      Parameters:
      ex - the exception to wrap
      Returns:
      a new wrapped exception containing the provided exception
    • unwrap

      @NonNull public static Throwable unwrap(@NonNull ExceptionUtils.WrappedException ex)
      Unwrap a previously wrapped exception.
      Parameters:
      ex - the wrapped exception to unwrap
      Returns:
      the original exception that was wrapped
    • unwrap

      @NonNull public static <E extends Throwable> E unwrap(@NonNull ExceptionUtils.WrappedException ex, @NonNull Class<E> wrappedExceptionClass)
      Unwrap a previously wrapped exception, casting it to the expected type.
      Type Parameters:
      E - the expected exception type
      Parameters:
      ex - the wrapped exception to unwrap
      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