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)
| 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 |