com.github.markozajc.ef.consumer.execpt.EIntConsumer Maven / Gradle / Ivy
package com.github.markozajc.ef.consumer.execpt;
import static com.github.markozajc.ef.Utilities.asUnchecked;
import java.util.function.IntConsumer;
/**
* Variant of {@link IntConsumer} capable of throwing a generic {@link Throwable}.
*
* @author Marko Zajc
*
* @param
* {@link Throwable} type
*/
@FunctionalInterface
public interface EIntConsumer extends IntConsumer {
@Override
default void accept(int p) {
try {
acceptChecked(p);
} catch (Throwable e) { // NOSONAR can't catch generic exceptions
throw asUnchecked(e);
}
}
/**
* Same as {@link #accept(int)}, but throws a checked exception.
*
* @param p
* the input argument
*
* @throws E
* the defined exception type
*/
void acceptChecked(int p) throws E;
}