@Test(expectedExceptions = RuntimeException.class) public void testOnThrowableWhenFirstThrowsUnmatchingException() { Suppliers2.onThrowable(new Supplier<String>() { @Override public String get() { throw new RuntimeException(); } }, NoSuchElementException.class, Suppliers.ofInstance("foo")).get(); }
@Beta public static <T, X extends Throwable> Supplier<T> onThrowable(final Supplier<T> unlessThrowable, final Class<X> throwable, final Supplier<T> fallback) { return new Supplier<T>() { @Override public T get() { try { return unlessThrowable.get(); } catch (Throwable t) { if (Throwables2.getFirstThrowableOfType(t, throwable) != null) return fallback.get(); throw Throwables.propagate(t); } } @Override public String toString() { return MoreObjects.toStringHelper(this).add("unlessThrowable", unlessThrowable) .add("throwable", throwable.getSimpleName()).add("fallback", fallback).toString(); } }; }
Suppliers2 { @Beta public static <T, X extends Throwable> Supplier<T> onThrowable(final Supplier<T> unlessThrowable, final Class<X> throwable, final Supplier<T> fallback) { return new Supplier<T>() { @Override public T get() { try { return unlessThrowable.get(); } catch (Throwable t) { if (Throwables2.getFirstThrowableOfType(t, throwable) != null) return fallback.get(); throw Throwables.propagate(t); } } @Override public String toString() { return MoreObjects.toStringHelper(this).add("unlessThrowable", unlessThrowable) .add("throwable", throwable.getSimpleName()).add("fallback", fallback).toString(); } }; } }
Suppliers2 { @Beta public static <T, X extends Throwable> Supplier<T> onThrowable(final Supplier<T> unlessThrowable, final Class<X> throwable, final Supplier<T> fallback) { return new Supplier<T>() { @Override public T get() { try { return unlessThrowable.get(); } catch (Throwable t) { if (Throwables2.getFirstThrowableOfType(t, throwable) != null) return fallback.get(); throw Throwables.propagate(t); } } @Override public String toString() { return MoreObjects.toStringHelper(this).add("unlessThrowable", unlessThrowable) .add("throwable", throwable.getSimpleName()).add("fallback", fallback).toString(); } }; }  }
Suppliers2 { @Beta public static <T, X extends Throwable> Supplier<T> onThrowable(final Supplier<T> unlessThrowable, final Class<X> throwable, final Supplier<T> fallback) { return new Supplier<T>() { @Override public T get() { try { return unlessThrowable.get(); } catch (Throwable t) { if (Throwables2.getFirstThrowableOfType(t, throwable) != null) return fallback.get(); throw Throwables.propagate(t); } } @Override public String toString() { return MoreObjects.toStringHelper(this).add("unlessThrowable", unlessThrowable) .add("throwable", throwable.getSimpleName()).add("fallback", fallback).toString(); } }; }  static Supplier<V> getLastValueInMap(final Supplier<Map<K, Supplier<V>>> input); static Supplier<V> getValueInMapOrNull(final Supplier<Map<K, Supplier<V>>> input, final K keyValue); static Function<X, Supplier<X>> ofInstanceFunction(); @Beta static Supplier<T> or(final Supplier<T> unlessNull, final Supplier<T> fallback); @Beta static Supplier<T> onThrowable(final Supplier<T> unlessThrowable,
            final Class<X> throwable, final Supplier<T> fallback); }
Suppliers2 { @Beta public static <T, X extends Throwable> Supplier<T> onThrowable(final Supplier<T> unlessThrowable, final Class<X> throwable, final Supplier<T> fallback) { return new Supplier<T>() { @Override public T get() { try { return unlessThrowable.get(); } catch (Throwable t) { if (Throwables2.getFirstThrowableOfType(t, throwable) != null) return fallback.get(); throw Throwables.propagate(t); } } @Override public String toString() { return MoreObjects.toStringHelper(this).add("unlessThrowable", unlessThrowable) .add("throwable", throwable.getSimpleName()).add("fallback", fallback).toString(); } }; }  static Supplier<V> getLastValueInMap(final Supplier<Map<K, Supplier<V>>> input); static Supplier<V> getValueInMapOrNull(final Supplier<Map<K, Supplier<V>>> input, final K keyValue); static Function<X, Supplier<X>> ofInstanceFunction(); @Beta static Supplier<T> or(final Supplier<T> unlessNull, final Supplier<T> fallback); @Beta static Supplier<T> onThrowable(final Supplier<T> unlessThrowable,
            final Class<X> throwable, final Supplier<T> fallback);  }