Interface ThrowingConsumer<T>
- Type Parameters:
T- the type of the input to the operation
- All Superinterfaces:
Consumer<T>
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
A
Consumer that allows invocation of code that throws a checked
exception.- Since:
- 6.0
- Author:
- Stephane Nicoll, Phillip Webb
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidDefaultConsumer.accept(Object)that wraps any thrown checked exceptions (by default in aRuntimeException).default voidaccept(T t, BiFunction<String, Exception, RuntimeException> exceptionWrapper) Performs this operation on the given argument, wrapping any thrown checked exceptions using the givenexceptionWrapper.voidPerforms this operation on the given argument, possibly throwing a checked exception.static <T> ThrowingConsumer<T>of(ThrowingConsumer<T> consumer) Lambda friendly convenience method that can be used to createThrowingConsumerwhere theaccept(Object)method wraps any thrown checked exceptions using the givenexceptionWrapper.static <T> ThrowingConsumer<T>of(ThrowingConsumer<T> consumer, BiFunction<String, Exception, RuntimeException> exceptionWrapper) Lambda friendly convenience method that can be used to createThrowingConsumerwhere theaccept(Object)method wraps any thrown checked exceptions using the givenexceptionWrapper.default ThrowingConsumer<T>throwing(BiFunction<String, Exception, RuntimeException> exceptionWrapper) Return a newThrowingConsumerwhere theaccept(Object)method wraps any thrown checked exceptions using the givenexceptionWrapper.
-
Method Details
-
acceptWithException
Performs this operation on the given argument, possibly throwing a checked exception.- Parameters:
t- the input argument- Throws:
Exception- on error
-
accept
DefaultConsumer.accept(Object)that wraps any thrown checked exceptions (by default in aRuntimeException). -
accept
Performs this operation on the given argument, wrapping any thrown checked exceptions using the givenexceptionWrapper.- Parameters:
exceptionWrapper-BiFunctionthat wraps the given message and checked exception into a runtime exception
-
throwing
default ThrowingConsumer<T> throwing(BiFunction<String, Exception, RuntimeException> exceptionWrapper) Return a newThrowingConsumerwhere theaccept(Object)method wraps any thrown checked exceptions using the givenexceptionWrapper.- Parameters:
exceptionWrapper-BiFunctionthat wraps the given message and checked exception into a runtime exception- Returns:
- the replacement
ThrowingConsumerinstance
-
of
Lambda friendly convenience method that can be used to createThrowingConsumerwhere theaccept(Object)method wraps any thrown checked exceptions using the givenexceptionWrapper.- Type Parameters:
T- the type of the input to the operation- Parameters:
consumer- the source consumer- Returns:
- a new
ThrowingConsumerinstance
-
of
static <T> ThrowingConsumer<T> of(ThrowingConsumer<T> consumer, BiFunction<String, Exception, RuntimeException> exceptionWrapper) Lambda friendly convenience method that can be used to createThrowingConsumerwhere theaccept(Object)method wraps any thrown checked exceptions using the givenexceptionWrapper.- Type Parameters:
T- the type of the input to the operation- Parameters:
consumer- the source consumerexceptionWrapper- the exception wrapper to use- Returns:
- a new
ThrowingConsumerinstance
-