Interface ThrowingRunnable<X extends Throwable>
- Type Parameters:
X- the type of the exception thrown by the function
- All Superinterfaces:
Runnable
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
An extension of
Runnable allowing throwing calls in its body.-
Method Summary
Modifier and TypeMethodDescriptionstatic <@Any X extends Throwable>
@NotNull ThrowingRunnable<X>empty()Creates an empty (no-op) throwing runnable.default voidrun()voidRuns an action.static <@Any X extends Throwable>
@NotNull ThrowingRunnable<X>Creates a throwing runnable which always throws an exception produced by using the factory.
-
Method Details
-
runChecked
Runs an action.- Throws:
X- if an exception happens
-
run
default void run() -
empty
Creates an empty (no-op) throwing runnable.- Type Parameters:
X- any formal type of the (never thrown) exception- Returns:
- empty throwing runnable
-
throwing
@NotNull static <@Any X extends Throwable> @NotNull ThrowingRunnable<X> throwing(@NonNull @NonNull Supplier<? extends @NotNull X> exceptionFactory) Creates a throwing runnable which always throws an exception produced by using the factory.- Type Parameters:
X- the type of the exception thrown by the function- Parameters:
exceptionFactory- factory used for creation of the exception- Returns:
- throwing runnable which always throws
Xby creating it via the provided factory - Throws:
NullPointerException- ifexceptionFactoryisnull- API note
- if the
exceptionFactoryproducesnullthenNullPointerExceptionwill be thrown when attempting to throw the expected exception
-