private static <V, X extends Throwable> V fnUnwrap(Supplier<V> fn, Class<? extends X> type) { try { return fn.tryGet(); } catch (Throwable x) { if (isFatal(x)) { throw sneakyThrow(x); } Throwable t = x; if (type.isInstance(x)) { t = Optional.ofNullable(x.getCause()).orElse(x); } throw sneakyThrow(t); } }
private static <X extends Throwable> void runUnwrap(Runnable action, Class<? extends X> type) { try { action.tryRun(); } catch (Throwable x) { if (isFatal(x)) { throw sneakyThrow(x); } Throwable t = x; if (type.isInstance(x)) { t = Optional.ofNullable(x.getCause()).orElse(x); } throw sneakyThrow(t); } }
private static <R, X extends Throwable> R fnRecover(Supplier<R> fn, Class<? extends X> type, java.util.function.Function<X, R> recover) { try { return fn.tryGet(); } catch (Throwable x) { if (isFatal(x)) { throw sneakyThrow(x); } if (type.isInstance(x)) { return recover.apply(type.cast(x)); } throw sneakyThrow(x); } }
private static void runWrap(Runnable action, java.util.function.Function<Throwable, Exception> wrapper) { try { action.tryRun(); } catch (Throwable x) { if (isFatal(x)) { throw sneakyThrow(x); } throw sneakyThrow(wrapper.apply(x)); } }
private static <V> V fnWrap(Supplier<V> fn, java.util.function.Function<Throwable, Exception> wrapper) { try { return fn.tryGet(); } catch (Throwable x) { if (isFatal(x)) { throw sneakyThrow(x); } throw sneakyThrow(wrapper.apply(x)); } }
private static <R> R fn(Supplier<R> fn, Supplier<R> orElse) { try { return fn.tryGet(); } catch (Throwable x) { if (isFatal(x)) { throw sneakyThrow(x); } return orElse.get(); } }