Package org.kiwiproject.base
Interface CatchingRunnable
- 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.
Extension of
Runnable that never lets exceptions escape. Useful for things like scheduled executions
using ScheduledExecutorService where an intermittent error should not cause the
executor to suppress future executions (which is the default behavior).-
Method Summary
Modifier and TypeMethodDescriptiondefault voidhandleExceptionSafely(Exception exception) Handle an exception thrown byrunSafely().default voidrun()WrapsrunSafely()in a try/catch.voidThe logic that could throw aRuntimeException.
-
Method Details
-
run
default void run()WrapsrunSafely()in a try/catch. Logs exceptions and will callhandleExceptionSafely(Exception)to permit handling of any thrown exceptions. -
handleExceptionSafely
Handle an exception thrown byrunSafely().- Parameters:
exception- theExceptionto handle
-
runSafely
void runSafely()The logic that could throw aRuntimeException.
-