All Downloads are FREE. Search and download functionalities are using the official Maven repository.

aQute.bnd.exceptions.BiConsumerWithException Maven / Gradle / Ivy

The newest version!
package aQute.bnd.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();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy