Interface ThrowingConsumer<T>

Type Parameters:
T - the type of argument consumed
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface @API(status=STABLE, since="5.0") 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.

Rationale for throwing 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.

Since:
5.0
See Also:
Consumer, DynamicTest.stream(java.util.Iterator<T>, java.util.function.Function<? super T, java.lang.String>, org.junit.jupiter.api.function.ThrowingConsumer<? super T>), Executable, ThrowingSupplier
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    accept​(T t)
    Consume the supplied argument, potentially throwing an exception.
  • Method Details

    • accept

      void accept(T t) throws Throwable
      Consume the supplied argument, potentially throwing an exception.
      Parameters:
      t - the argument to consume
      Throws:
      Throwable