aQute.lib.exceptions.Exceptions Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of biz.aQute.bndlib Show documentation
Show all versions of biz.aQute.bndlib Show documentation
bndlib: A Swiss Army Knife for OSGi
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);
}
}
};
}
}