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

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

The newest version!
package aQute.bnd.exceptions;

/**
 * Runnable interface that allows exceptions.
 */
@FunctionalInterface
public interface RunnableWithException {
	void run() throws Exception;

	default Runnable orElseThrow() {
		return () -> {
			try {
				run();
			} catch (Exception e) {
				throw Exceptions.duck(e);
			}
		};
	}

	default Runnable ignoreException() {
		return () -> {
			try {
				run();
			} catch (Exception e) {}
		};
	}

	static Runnable asRunnable(RunnableWithException unchecked) {
		return unchecked.orElseThrow();
	}

	static Runnable asRunnableIgnoreException(RunnableWithException unchecked) {
		return unchecked.ignoreException();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy