Interface RunnableWithException<E extends Exception>
-
- Type Parameters:
E
- the type of the potential exception of the operation
- All Superinterfaces:
ExceptionHandlerSupport<Runnable,Runnable,RunnableWithException<E>>
,NoReturnExceptionHandlerSupport<Runnable,Supplier<CompletionStage<Void>>,RunnableWithException<E>>
- 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 RunnableWithException<E extends Exception> extends NoReturnExceptionHandlerSupport<Runnable,Supplier<CompletionStage<Void>>,RunnableWithException<E>>
Represents an operation that accepts no input argument and returns no result and may throw exception. Unlike most other functional interfaces,RunnableWithException
is expected to operate via side-effects.General contract
void run() throws E
- The functional method.- uncheck - Return a
Runnable
- lift - Return a
Runnable
- ignore - Return a
Runnable
- See Also:
Runnable
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default RunnableWithException<E>
andThen(RunnableWithException<? extends E> after)
Returns a composedRunnableWithException
that performs, in sequence, this operation followed by theafter
operation.static <T,R,E extends Exception>
FunctionWithException<T,R,E>asFunction(RunnableWithException<E> operation)
Converts aRunnableWithException
to aFunctionWithException
returningnull
and ignoring input.static <E extends Exception>
RunnableWithException<E>failing(Supplier<E> exceptionBuilder)
Returns an operation that always throw exception.default Runnable
ignore()
Converts thisRunnableWithException
to a liftedRunnable
ignoring exception.static <E extends Exception>
Runnableignored(RunnableWithException<E> operation)
Converts aRunnableWithException
to a liftedRunnable
ignoring exception.static <E extends Exception>
Runnablelifted(RunnableWithException<E> operation)
Converts aRunnableWithException
to a liftedRunnable
ignoring exception.void
run()
Performs this operation.default Supplier<CompletionStage<Void>>
stage()
Converts thisRunnableWithException
to a stagedSupplier
that return aCompletionStage
.static <E extends Exception>
Supplier<CompletionStage<Void>>staged(RunnableWithException<E> operation)
Converts aRunnableWithException
to a stagedSupplier
.default Runnable
uncheck()
Converts thisRunnableWithException
to aRunnable
that wraps exception toRuntimeException
.static <E extends Exception>
Runnableunchecked(RunnableWithException<E> operation)
Converts aRunnableWithException
to aRunnable
that wraps exception toRuntimeException
.static <E extends Exception>
Runnableunchecked(RunnableWithException<E> operation, Function<Exception,RuntimeException> exceptionMapper)
Converts aRunnableWithException
to aRunnable
that wraps exception toRuntimeException
by using the provided mapping function.-
Methods inherited from interface ch.powerunit.extensions.exceptions.ExceptionHandlerSupport
documented, exceptionMapper
-
Methods inherited from interface ch.powerunit.extensions.exceptions.NoReturnExceptionHandlerSupport
lift, notThrowingHandler, throwingHandler
-
-
-
-
Method Detail
-
run
void run() throws E extends Exception
Performs this operation.- Throws:
E
- any exceptionE extends Exception
- See Also:
Runnable.run()
-
uncheck
default Runnable uncheck()
Converts thisRunnableWithException
to aRunnable
that wraps exception toRuntimeException
.- Specified by:
uncheck
in interfaceExceptionHandlerSupport<Runnable,Runnable,RunnableWithException<E extends Exception>>
- Specified by:
uncheck
in interfaceNoReturnExceptionHandlerSupport<Runnable,Supplier<CompletionStage<Void>>,RunnableWithException<E extends Exception>>
- Returns:
- the unchecked operation
- See Also:
unchecked(RunnableWithException)
,unchecked(RunnableWithException, Function)
-
ignore
default Runnable ignore()
Converts thisRunnableWithException
to a liftedRunnable
ignoring exception.- Specified by:
ignore
in interfaceExceptionHandlerSupport<Runnable,Runnable,RunnableWithException<E extends Exception>>
- Specified by:
ignore
in interfaceNoReturnExceptionHandlerSupport<Runnable,Supplier<CompletionStage<Void>>,RunnableWithException<E extends Exception>>
- Returns:
- the operation that ignore error
- See Also:
ignored(RunnableWithException)
-
stage
default Supplier<CompletionStage<Void>> stage()
Converts thisRunnableWithException
to a stagedSupplier
that return aCompletionStage
.- Specified by:
stage
in interfaceNoReturnExceptionHandlerSupport<Runnable,Supplier<CompletionStage<Void>>,RunnableWithException<E extends Exception>>
- Returns:
- the staged operation.
- Since:
- 1.1.0
-
andThen
default RunnableWithException<E> andThen(RunnableWithException<? extends E> after)
Returns a composedRunnableWithException
that performs, in sequence, this operation followed by theafter
operation. If performing either operation throws an exception, it is relayed to the caller of the composed operation. If performing this operation throws an exception, theafter
operation will not be performed.- Parameters:
after
- the operation to perform after this operation- Returns:
- a composed
RunnableWithException
that performs in sequence this operation followed by theafter
operation - Throws:
NullPointerException
- ifafter
is null- Since:
- 1.2.0
-
failing
static <E extends Exception> RunnableWithException<E> failing(Supplier<E> exceptionBuilder)
Returns an operation that always throw exception.- Type Parameters:
E
- the type of the exception- Parameters:
exceptionBuilder
- the supplier to create the exception- Returns:
- an operation that always throw exception
-
unchecked
static <E extends Exception> Runnable unchecked(RunnableWithException<E> operation)
Converts aRunnableWithException
to aRunnable
that wraps exception toRuntimeException
.- Type Parameters:
E
- the type of the potential exception- Parameters:
operation
- to be unchecked- Returns:
- the unchecked exception
- Throws:
NullPointerException
- if operation is null- See Also:
uncheck()
,unchecked(RunnableWithException, Function)
-
unchecked
static <E extends Exception> Runnable unchecked(RunnableWithException<E> operation, Function<Exception,RuntimeException> exceptionMapper)
Converts aRunnableWithException
to aRunnable
that wraps exception toRuntimeException
by using the provided mapping function.- Type Parameters:
E
- the type of the potential exception- Parameters:
operation
- the be uncheckedexceptionMapper
- a function to convert the exception to the runtime exception.- Returns:
- the unchecked exception
- Throws:
NullPointerException
- if operation or exceptionMapper is null- See Also:
uncheck()
,unchecked(RunnableWithException)
-
lifted
static <E extends Exception> Runnable lifted(RunnableWithException<E> operation)
Converts aRunnableWithException
to a liftedRunnable
ignoring exception.- Type Parameters:
E
- the type of the potential exception- Parameters:
operation
- to be lifted- Returns:
- the lifted operation
- Throws:
NullPointerException
- if operation is null- See Also:
NoReturnExceptionHandlerSupport.lift()
-
ignored
static <E extends Exception> Runnable ignored(RunnableWithException<E> operation)
Converts aRunnableWithException
to a liftedRunnable
ignoring exception.- Type Parameters:
E
- the type of the potential exception- Parameters:
operation
- to be lifted- Returns:
- the lifted operation
- Throws:
NullPointerException
- if operation is null- Since:
- 1.1.0
- See Also:
ignore()
-
staged
static <E extends Exception> Supplier<CompletionStage<Void>> staged(RunnableWithException<E> operation)
Converts aRunnableWithException
to a stagedSupplier
.- Type Parameters:
E
- the type of the potential exception- Parameters:
operation
- to be staged- Returns:
- the staged operation
- Throws:
NullPointerException
- if operation is null
-
asFunction
static <T,R,E extends Exception> FunctionWithException<T,R,E> asFunction(RunnableWithException<E> operation)
Converts aRunnableWithException
to aFunctionWithException
returningnull
and ignoring input.- Type Parameters:
T
- the type of the input to the operationR
- the type of the return valueE
- the type of the potential exception- Parameters:
operation
- to be converted- Returns:
- the function
- Throws:
NullPointerException
- if operation is null- Since:
- 1.2.0
-
-