java.lang.Object
dev.metaschema.core.util.ExceptionUtils
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA runtime exception that wraps a checked exception, allowing it to be thrown from contexts that do not allow checked exceptions (such as lambda expressions). -
Method Summary
Modifier and TypeMethodDescriptionstatic ThrowableUnwrap a previously wrapped exception.static <E extends Throwable>
Eunwrap(ExceptionUtils.WrappedException ex, Class<E> wrappedExceptionClass) Unwrap a previously wrapped exception, casting it to the expected type.Wrap a checked exception in an uncheckedExceptionUtils.WrappedException.Wrap a checked exception in an uncheckedExceptionUtils.WrappedException.
-
Method Details
-
wrap
Wrap a checked exception in an uncheckedExceptionUtils.WrappedException.- Parameters:
ex- the exception to wrap- Returns:
- a new wrapped exception containing the provided exception
-
wrapAndThrow
Wrap a checked exception in an uncheckedExceptionUtils.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
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 unwrapwrappedExceptionClass- 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
-