Skip to content

Instantly share code, notes, and snippets.

@bvn13
Created February 2, 2022 15:55
Show Gist options
  • Save bvn13/d9c087eafb8abf4eb2ff7a78fa36ecad to your computer and use it in GitHub Desktop.
Save bvn13/d9c087eafb8abf4eb2ff7a78fa36ecad to your computer and use it in GitHub Desktop.
Functional interface ThrowingConsumer wrapping all catchable exceptions to be used in Lambdas
import java.util.function.Consumer;
@FunctionalInterface
public interface ThrowingConsumer<T> extends Consumer<T> {
@Override
default void accept(final T elem) {
try {
acceptThrows(elem);
} catch (final Exception e) {
throw new RuntimeException(e);
}
}
void acceptThrows(T elem) throws Exception;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment