Interface FunctionWithException<T, R, E extends Exception>
- Type Parameters:
T- the input typeR- the result typeE- the checked exception type
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
A function whose operation may throw a checked exception, with adapters for APIs that accept ordinary
functions.- Since:
- 3.31
- Author:
- Eike Stepper
-
Method Summary
Modifier and TypeMethodDescriptionApplies this function to an input value.function(FunctionWithException<T, R, E> function) Adapts a checked-exception function to a regularFunction.function(FunctionWithException<T, R, E> function, Class<E> exceptionClass, Consumer<E> exceptionHandler) Adapts a checked-exception function to a regularFunction.
-
Method Details
-
apply
-
function
Adapts a checked-exception function to a regularFunction. Any caught exception is wrapped in aRuntimeException.- Parameters:
function- the checked-exception function- Returns:
- a function that wraps checked exceptions
-
function
static <T, R, E extends Exception> Function<T,R> function(FunctionWithException<T, R, E> function, Class<E> exceptionClass, Consumer<E> exceptionHandler) Adapts a checked-exception function to a regularFunction. If an exception handler is supplied, exceptions matchingexceptionClassare passed to it. As withConsumerWithException, the original exception is then wrapped in aRuntimeException; exceptions of other types skip the handler and are wrapped directly.- Parameters:
function- the checked-exception functionexceptionClass- the exception type accepted by the handler, ornullwhen no handler is usedexceptionHandler- the optional handler for the selected exception type- Returns:
- a function that handles matching exceptions and wraps them
-