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,RunnableWithExceptionis 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 composedRunnableWithExceptionthat performs, in sequence, this operation followed by theafteroperation.static <T,R,E extends Exception>
FunctionWithException<T,R,E>asFunction(RunnableWithException<E> operation)Converts aRunnableWithExceptionto aFunctionWithExceptionreturningnulland ignoring input.static <E extends Exception>
RunnableWithException<E>failing(Supplier<E> exceptionBuilder)Returns an operation that always throw exception.default Runnableignore()Converts thisRunnableWithExceptionto a liftedRunnableignoring exception.static <E extends Exception>
Runnableignored(RunnableWithException<E> operation)Converts aRunnableWithExceptionto a liftedRunnableignoring exception.static <E extends Exception>
Runnablelifted(RunnableWithException<E> operation)Converts aRunnableWithExceptionto a liftedRunnableignoring exception.voidrun()Performs this operation.default Supplier<CompletionStage<Void>>stage()Converts thisRunnableWithExceptionto a stagedSupplierthat return aCompletionStage.static <E extends Exception>
Supplier<CompletionStage<Void>>staged(RunnableWithException<E> operation)Converts aRunnableWithExceptionto a stagedSupplier.default Runnableuncheck()Converts thisRunnableWithExceptionto aRunnablethat wraps exception toRuntimeException.static <E extends Exception>
Runnableunchecked(RunnableWithException<E> operation)Converts aRunnableWithExceptionto aRunnablethat wraps exception toRuntimeException.static <E extends Exception>
Runnableunchecked(RunnableWithException<E> operation, Function<Exception,RuntimeException> exceptionMapper)Converts aRunnableWithExceptionto aRunnablethat wraps exception toRuntimeExceptionby 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 thisRunnableWithExceptionto aRunnablethat wraps exception toRuntimeException.- Specified by:
uncheckin interfaceExceptionHandlerSupport<Runnable,Runnable,RunnableWithException<E extends Exception>>- Specified by:
uncheckin 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 thisRunnableWithExceptionto a liftedRunnableignoring exception.- Specified by:
ignorein interfaceExceptionHandlerSupport<Runnable,Runnable,RunnableWithException<E extends Exception>>- Specified by:
ignorein 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 thisRunnableWithExceptionto a stagedSupplierthat return aCompletionStage.- Specified by:
stagein 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 composedRunnableWithExceptionthat performs, in sequence, this operation followed by theafteroperation. If performing either operation throws an exception, it is relayed to the caller of the composed operation. If performing this operation throws an exception, theafteroperation will not be performed.- Parameters:
after- the operation to perform after this operation- Returns:
- a composed
RunnableWithExceptionthat performs in sequence this operation followed by theafteroperation - Throws:
NullPointerException- ifafteris 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 aRunnableWithExceptionto aRunnablethat 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 aRunnableWithExceptionto aRunnablethat wraps exception toRuntimeExceptionby 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 aRunnableWithExceptionto a liftedRunnableignoring 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 aRunnableWithExceptionto a liftedRunnableignoring 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 aRunnableWithExceptionto 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 aRunnableWithExceptionto aFunctionWithExceptionreturningnulland 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
-
-