MCPcopy
hub / github.com/google/guava / throwIfInstanceOf

Method throwIfInstanceOf

guava/src/com/google/common/base/Throwables.java:72–79  ·  view source on GitHub ↗

Throws {@code throwable} if it is an instance of {@code declaredType}. Example usage: <pre> for (Foo foo : foos) { try { foo.bar(); } catch (BarException | RuntimeException | Error t) { failure = t; } } if (failure != null) { throwIfInstanceOf(failure, BarException.class); throwIf

(
      Throwable throwable, Class<X> declaredType)

Source from the content-addressed store, hash-verified

70 * @since 20.0
71 */
72 @GwtIncompatible // Class.cast, Class.isInstance
73 public static <X extends Throwable> void throwIfInstanceOf(
74 Throwable throwable, Class<X> declaredType) throws X {
75 checkNotNull(throwable);
76 if (declaredType.isInstance(throwable)) {
77 throw declaredType.cast(throwable);
78 }
79 }
80
81 /**
82 * Propagates {@code throwable} exactly as-is, if and only if it is an instance of {@code

Calls 2

checkNotNullMethod · 0.45
castMethod · 0.45