Top Description Methods
org.junit.jupiter.api.function

public Interface ThrowingConsumer<T extends @Nullable Object>

Annotations
@FunctionalInterface
@API
status:STABLE
since:5.0
Type Parameters
<T>
the type of argument consumed
Static Imports
org.apiguardian.api.API.Status.STABLE

ThrowingConsumer is a functional interface that can be used to implement any generic block of code that consumes an argument and potentially throws a Throwable.

The ThrowingConsumer interface is similar to java.util.function.Consumer, except that a ThrowingConsumer can throw any kind of exception, including checked exceptions.

Rationale for throwing Throwable instead of Exception

Although Java applications typically throw exceptions that are instances of java.lang.Exception, java.lang.RuntimeException, java.lang.Error, or java.lang.AssertionError (in testing scenarios), there may be use cases where a ThrowingConsumer needs to explicitly throw a Throwable. In order to support such specialized use cases, accept is declared to throw Throwable.

Since
5.0
See Also
java.util.function.Consumer, org.junit.jupiter.api.DynamicTest#stream, Executable, ThrowingSupplier

Method Summary

Modifier and TypeMethod and Description
public void
accept(T
the argument to consume
t
)

Consume the supplied argument, potentially throwing an exception.

Method Detail

acceptback to summary
public void accept(T t) throws Throwable

Consume the supplied argument, potentially throwing an exception.

Parameters
t:T

the argument to consume