Package com.diffplug.spotless
Class ThrowingEx
java.lang.Object
com.diffplug.spotless.ThrowingEx
Basic functional interfaces which throw exception, along with
static helper methods for calling them.
Contains most of the functionality of Durian's Throwing and Errors classes, but stripped down and renamed to avoid any confusion.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA bi-function that can throw any exception.static interfaceA function that can throw any exception.static interfaceA runnable that can throw any exception.static interfaceA supplier that can throw any exception.static classA RuntimeException specifically for the purpose of wrapping non-runtime Exceptions as RuntimeExceptions. -
Method Summary
Modifier and TypeMethodDescriptionstatic RuntimeExceptionCasts or wraps the given exception to be a RuntimeException.static <T> Tget(ThrowingEx.Supplier<T> supplier) Gets the given value, rethrowing any exceptions as runtime exceptions.static voidrun(ThrowingEx.Runnable runnable) Runs the given runnable, rethrowing any exceptions as runtime exceptions.static Stringstatic RuntimeExceptionUtility method for rethrowing an exception's cause with as few wrappers as possible.static <T,R> Function<T, R> wrap(ThrowingEx.Function<T, R> function) Wraps the givenThrowingEx.Functionas a standardFunction, rethrowing any exceptions as runtime exceptions.
-
Method Details
-
run
Runs the given runnable, rethrowing any exceptions as runtime exceptions. -
get
Gets the given value, rethrowing any exceptions as runtime exceptions. -
wrap
Wraps the givenThrowingEx.Functionas a standardFunction, rethrowing any exceptions as runtime exceptions. -
asRuntime
Casts or wraps the given exception to be a RuntimeException.If the input exception is a RuntimeException, it is simply cast and returned. Otherwise, it wrapped in a
ThrowingEx.WrappedAsRuntimeExceptionand returned. -
unwrapCause
Utility method for rethrowing an exception's cause with as few wrappers as possible.try { doSomething(); } catch (Throwable e) { throw unwrapCause(e); } -
stacktrace
-