- Type Parameters:
T
- The type of the object to consume.E
- The type of the exception that can be thrown.
public interface ThrowingConsumer<T,E extends Throwable>
Wraps a consumer that throws an exception and allows it to be used in a lambda.
This is as an alternative to the Consumer
interface, which does not allow checked
exceptions to be thrown.
Example:
ThrowingConsumer<String, IOException> consumer = s -> {
// do something that throws an IOException
throw new IOException("test");
};
-
Method Summary
-
Method Details
-
accept
Accept an object.See
Consumer.accept(Object)
for more information on how consumers work. This method is identical, except that it allows checked exceptions to be thrown.- Parameters:
t
- The object to accept.- Throws:
E
- The exception that can be thrown.
-