Interface ThrowingConsumer5<A,B,C,D,E>
- 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.D- The type of the fourth argument to the operation.E- The type of the fifth argument to the operation.
- All Superinterfaces:
Consumer5<A,B, C, D, E>
- 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 Consumer5 to allow the functional method
to throw checked exceptions. The default apply(Object, Object, Object, Object, Object) method wraps any checked exceptions in a
RuntimeException, making it compatible with standard Consumer5 usage while still allowing
the implementation to throw checked exceptions via acceptThrows(Object, Object, 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, Object, Object) - Compatible with Consumer5 - implements
Consumer5.apply(Object, Object, Object, Object, Object)by wrapping exceptions - Dual interface - can be used as both Consumer5 and ThrowingConsumer5
Use Cases:
- Five-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, Object, Object)- Throws checked exceptions directlyapply(Object, Object, Object, Object, Object)- Wraps checked exceptions inRuntimeException- Use
acceptThrowswhen you need to handle specific checked exceptions - Use
applywhen you want standard Consumer5 behavior
See Also:
ThrowingConsumer- Single-argument consumer that throws exceptionsThrowingConsumer2- Two-argument consumer that throws exceptionsThrowingConsumer3- Three-argument consumer that throws exceptionsThrowingConsumer4- Four-argument consumer that throws exceptions- juneau-commons Basics
-
Method Summary
Modifier and TypeMethodDescriptionvoidPerforms this operation on the given arguments, potentially throwing a checked exception.Returns a composedThrowingConsumer5that 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
Consumer5. It callsacceptThrows(Object, Object, Object, Object, Object)and wraps any checked exceptions.- Specified by:
applyin interfaceConsumer5<A,B, C, D, E> - Parameters:
a- The first operation argument.b- The second operation argument.c- The third operation argument.d- The fourth operation argument.e- The fifth operation argument.- Throws:
RuntimeException- ifacceptThrows(Object, Object, Object, Object, Object)throws a checked exception.
-
andThen
default ThrowingConsumer5<A,B, andThenC, D, E> (ThrowingConsumer5<? super A, ? super B, ? super C, ? super D, ? super E> after) Returns a composedThrowingConsumer5that 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
ThrowingConsumer5that 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
Consumer5.apply(Object, Object, Object, Object, Object)method.Example:
ThrowingConsumer5<String,Integer,Boolean,Double,Long>
validator = (name ,age ,active ,score ,timestamp ) -> {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 , 0.0, 0L); }catch (ValidationExceptione ) {// Handle checked exception }- Parameters:
a- The first operation argument.b- The second operation argument.c- The third operation argument.d- The fourth operation argument.e- The fifth operation argument.- Throws:
Exception- If an error occurs during operation execution.
-