Interface ThrowingConsumer<T>

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

@FunctionalInterface public interface ThrowingConsumer<T>
Functional counterpart to Consumer that allows the accept(Object) method to throw a checked Exception.

This is useful when working with streams or other functional APIs that need to propagate exceptions.

  • Method Summary

    Modifier and Type
    Method
    Description
    void
    accept(T t)
    Performs this operation on the given argument.
    andThen(@NonNull ThrowingConsumer<? super T> after)
    Returns a composed consumer that performs, in sequence, this operation followed by the after operation.
  • Method Details

    • accept

      void accept(T t) throws Exception
      Performs this operation on the given argument.
      Parameters:
      t - the input argument
      Throws:
      Exception - if unable to process the argument
    • andThen

      default ThrowingConsumer<T> andThen(@NonNull @NonNull ThrowingConsumer<? super T> after)
      Returns a composed consumer that performs, in sequence, this operation followed by the after operation.
      Parameters:
      after - the operation to perform after this operation
      Returns:
      a composed ThrowingConsumer