aQute.lib.exceptions.ConsumerWithException Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of org.bndtools.headless.build.plugin.ant Show documentation
Show all versions of org.bndtools.headless.build.plugin.ant Show documentation
org.bndtools.headless.build.plugin.ant
package aQute.lib.exceptions;
import java.util.function.Consumer;
/**
* Consumer interface that allows exceptions.
*
* @param the type of the argument
*/
@FunctionalInterface
public interface ConsumerWithException {
void accept(T t) throws Exception;
default Consumer orElseThrow() {
return t -> {
try {
accept(t);
} catch (Exception e) {
throw Exceptions.duck(e);
}
};
}
default Consumer ignoreException() {
return t -> {
try {
accept(t);
} catch (Exception e) {}
};
}
static Consumer asConsumer(ConsumerWithException unchecked) {
return unchecked.orElseThrow();
}
static Consumer asConsumerIgnoreException(ConsumerWithException unchecked) {
return unchecked.ignoreException();
}
}