Interface SafeRunnable
-
- All Superinterfaces:
java.lang.Runnable
- All Known Implementing Classes:
SafeRunnable
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface SafeRunnable extends java.lang.Runnable
A runnable that catches runtime exceptions.
-
-
Field Summary
Fields Modifier and Type Field Description static org.slf4j.Logger
LOGGER
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default void
run()
void
safeRun()
static SafeRunnable
safeRun(java.lang.Runnable runnable)
Utility method to use SafeRunnable from lambdas.static SafeRunnable
safeRun(java.lang.Runnable runnable, java.util.function.Consumer<java.lang.Throwable> exceptionHandler)
Utility method to use SafeRunnable from lambdas with a custom exception handler.
-
-
-
Method Detail
-
run
default void run()
- Specified by:
run
in interfacejava.lang.Runnable
-
safeRun
void safeRun()
-
safeRun
static SafeRunnable safeRun(java.lang.Runnable runnable)
Utility method to use SafeRunnable from lambdas.Eg:
executor.submit(SafeRunnable.safeRun(() -> { // My not-safe code });
-
safeRun
static SafeRunnable safeRun(java.lang.Runnable runnable, java.util.function.Consumer<java.lang.Throwable> exceptionHandler)
Utility method to use SafeRunnable from lambdas with a custom exception handler.Eg:
executor.submit(SafeRunnable.safeRun(() -> { // My not-safe code }, exception -> { // Handle exception );
- Parameters:
runnable
-exceptionHandler
- handler that will be called when there are any exception- Returns:
-
-