Interface ThrowingConsumer3<A,B,C>
- Type Parameters:
A- The type of the first argument to the operation.B- The type of the second argument to the operation.C- The type of the third argument to the operation.
- All Superinterfaces:
Consumer3<A,B, C>
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
This interface extends Consumer3 to allow the functional method
to throw checked exceptions. The default apply(Object, Object, Object) method wraps any checked exceptions in a
RuntimeException, making it compatible with standard Consumer3 usage while still allowing
the implementation to throw checked exceptions via acceptThrows(Object, Object, Object).
Features:
- Functional interface - can be used with lambda expressions and method references
- Exception support - allows checked exceptions to be thrown via
acceptThrows(Object, Object, Object) - Compatible with Consumer3 - implements
Consumer3.apply(Object, Object, Object)by wrapping exceptions - Dual interface - can be used as both Consumer3 and ThrowingConsumer3
Use Cases:
- Three-argument operations that may throw I/O exceptions
- Validation operations that may throw validation exceptions
- Side-effect operations that may fail with checked exceptions
- Operations that need to propagate checked exceptions
Usage:
Exception Handling:
acceptThrows(Object, Object, Object)- Throws checked exceptions directlyapply(Object, Object, Object)- Wraps checked exceptions inRuntimeException- Use
acceptThrowswhen you need to handle specific checked exceptions - Use
applywhen you want standard Consumer3 behavior
See Also:
ThrowingConsumer- Single-argument consumer that throws exceptionsThrowingConsumer2- Two-argument consumer that throws exceptionsThrowingConsumer4- Four-argument consumer that throws exceptionsThrowingConsumer5- Five-argument consumer that throws exceptions- juneau-commons Basics
-
Method Summary
Modifier and TypeMethodDescriptionvoidacceptThrows(A a, B b, C c) Performs this operation on the given arguments, potentially throwing a checked exception.default ThrowingConsumer3<A,B, C> andThen(ThrowingConsumer3<? super A, ? super B, ? super C> after) Returns a composedThrowingConsumer3that performs, in sequence, this operation followed by theafteroperation.default voidPerforms this operation on the given arguments, wrapping any checked exceptions in aRuntimeException.
-
Method Details
-
apply
Performs this operation on the given arguments, wrapping any checked exceptions in aRuntimeException.This is the default implementation that makes this interface compatible with
Consumer3. It callsacceptThrows(Object, Object, Object)and wraps any checked exceptions.- Specified by:
applyin interfaceConsumer3<A,B, C> - Parameters:
a- The first operation argument.b- The second operation argument.c- The third operation argument.- Throws:
RuntimeException- ifacceptThrows(Object, Object, Object)throws a checked exception.
-
andThen
Returns a composedThrowingConsumer3that performs, in sequence, this operation followed by theafteroperation.This method enables operation composition, allowing you to chain multiple operations together. If performing either operation throws an exception, it is relayed to the caller of the composed operation. If performing this operation throws an exception, the
afteroperation will not be performed.- Parameters:
after- The operation to perform after this operation. Must not benull .- Returns:
- A composed
ThrowingConsumer3that performs in sequence this operation followed by theafteroperation. - Throws:
NullPointerException- ifafterisnull .
-
acceptThrows
Performs this operation on the given arguments, potentially throwing a checked exception.This is the functional method that implementations must provide. It allows checked exceptions to be thrown directly, unlike the standard
Consumer3.apply(Object, Object, Object)method.Example:
ThrowingConsumer3<String,Integer,Boolean>
validator = (name ,age ,active ) -> {if (name ==null ||name .isEmpty()) {throw new ValidationException("Name cannot be empty" ); }if (age < 0) {throw new ValidationException("Age cannot be negative" ); } };try {validator .acceptThrows("" , -1,true ); }catch (ValidationExceptione ) {// Handle checked exception }- Parameters:
a- The first operation argument.b- The second operation argument.c- The third operation argument.- Throws:
Exception- If an error occurs during operation execution.
-