@FunctionalInterface @API(value=Stable) public interface ThrowingConsumer<T>
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
Consumer
, except that a ThrowingConsumer
can throw any kind of exception, including checked exceptions.
Throwable
instead of Exception
Although Java applications typically throw exceptions that are instances
of Exception
, RuntimeException
,
Error
, or 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(T)
is declared to throw Throwable
.
Modifier and Type | Method and Description |
---|---|
void |
accept(T t)
Consume the supplied argument, potentially throwing an exception.
|