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

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

Go to download

This command line utility is the Swiss army knife of OSGi. It provides you with a breadth of tools to understand and manage OSGi based systems. This project basically uses bndlib.

There is a newer version: 7.1.0
Show newest version
package aQute.bnd.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();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy