aQute.lib.exceptions.BiConsumerWithException Maven / Gradle / Ivy
package aQute.lib.exceptions;
import java.util.function.BiConsumer;
/**
* BiConsumer interface that allows exceptions.
*
* @param the type of the first argument
* @param the type of the second argument
*/
@FunctionalInterface
public interface BiConsumerWithException {
void accept(T t, U u) throws Exception;
default BiConsumer orElseThrow() {
return (t, u) -> {
try {
accept(t, u);
} catch (Exception e) {
throw Exceptions.duck(e);
}
};
}
default BiConsumer ignoreException() {
return (t, u) -> {
try {
accept(t, u);
} catch (Exception e) {}
};
}
static BiConsumer asBiConsumer(BiConsumerWithException unchecked) {
return unchecked.orElseThrow();
}
static BiConsumer asBiConsumerIgnoreException(BiConsumerWithException unchecked) {
return unchecked.ignoreException();
}
}