Interface ThrowableConsumer<T,X extends Throwable>

Type Parameters:
T - The argument type
X - The exception that can be thrown
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 ThrowableConsumer<T,X extends Throwable>
Functional interface that takes one argument and consumes it.
The FunctionalInterface method is accept(Object).
The class is equivalent to Consumer, but the functional method can throw a checked exception.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    accept(T t)
    Functional method that takes one argument and consumes it.
    default @NotNull ThrowableConsumer<T,X>
    andThen(@NotNull ThrowableConsumer<? super T,X> after)
    Returns a composed consumer of same type that performs,
    in sequence, this operation followed by the after operation.
    static <T> @NotNull Consumer<T>
    caught(@NotNull ThrowableConsumer<T,? extends Throwable> consumer)
    Converts a throwable consumer into a consumer that throws a runtime exception when an exception is thrown.
  • Method Details

    • caught

      @NotNull static <T> @NotNull Consumer<T> caught(@NotNull @NotNull ThrowableConsumer<T,? extends Throwable> consumer)
      Converts a throwable consumer into a consumer that throws a runtime exception when an exception is thrown.
      Type Parameters:
      T - The argument type
      Parameters:
      consumer - The throwable consumer
      Returns:
      A caught consumer
      Throws:
      NullPointerException - If the throwable consumer is null
    • accept

      void accept(T t) throws X
      Functional method that takes one argument and consumes it.
      Parameters:
      t - The argument
      Throws:
      X - The exception that can be thrown
    • andThen

      @NotNull default @NotNull ThrowableConsumer<T,X> andThen(@NotNull @NotNull ThrowableConsumer<? super T,X> after)
      Returns a composed consumer of same type that performs,
      in sequence, this operation followed by the after operation.
      Parameters:
      after - The operation to perform after this operation
      Returns:
      The composed throwable consumer
      Throws:
      NullPointerException - If the after operation is null