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

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

There is a newer version: 7.0.0
Show newest version
package aQute.lib.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