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

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

There is a newer version: 7.0.0
Show newest version
package aQute.lib.exceptions;

public class Exceptions {
	private Exceptions() {}
	public static RuntimeException duck(Throwable t) {
		Exceptions. throwsUnchecked(t);
		throw new AssertionError("unreachable");
	}

	@SuppressWarnings("unchecked")
	private static  void throwsUnchecked(Throwable throwable) throws E {
		throw (E) throwable;
	}

	public static Runnable wrap(final RunnableWithException run) {
		return new Runnable() {

			@Override
			public void run() {
				try {
					run.run();
				} catch (Exception e) {
					throw duck(e);
				}
			}

		};
	}

	public static  org.osgi.util.function.Function wrap(final FunctionWithException run) {
		return new org.osgi.util.function.Function() {

			@Override
			public R apply(T value) {
				try {
					return run.apply(value);
				} catch (Exception e) {
					throw duck(e);
				}
			}
		};
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy