default BiFunction<T, U, R> asUnchecked() { return (t, u) -> { try { return ThrowingBiFunction.this.apply(t, u); } catch (RuntimeException | Error e) { throw e; } catch (Throwable e) { throw DiggExceptions.asUnchecked(e); } }; }
@Test public void runAThrowingRunnableUnchecked() { OneTimeToggle toggled = new OneTimeToggle(); DiggExceptions.runUnchecked( () -> toggled.nowOrIfAlreadyThenThrow(() -> new AssertionError("should not be run twice!"))); assertTrue(toggled.yet()); Exception e = new Exception(); try { runUnchecked( () -> { throw e; }); } catch (RuntimeException ex) { assertThat(ex.getCause(), sameInstance(e)); return; } fail("Should throw exception"); }