interface ConsumerE<T, E extends Exception> { void accept(T t) throws E; }
Note that Java 8 also includes specialized wrappers like RuntimeIOException. So it might be nice to extend your example:
static <T, E extends Exception> Consumer<T> wrapped( Function<? super E, RuntimeException> wrapper, ConsumerE<T, E> consumer) { return (t) -> { try { consumer.accept(t); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw wrapper.apply((E) e); } }; }
Consumer<String> printer = wrapped(RuntimeIOException::new, writer::write);
Note that Java 8 also includes specialized wrappers like RuntimeIOException. So it might be nice to extend your example:
Used as follows: