Throws throwable if it is a RuntimeException or Error. Example usage: for (Foo foo : foos) { try { foo.bar(); } catch (RuntimeException | Error t) { failure = t; } } if (failure != null) { throwIfUnchecked(failure); throw new AssertionError(failure);
(Throwable throwable)
| 127 | * @since 20.0 |
| 128 | */ |
| 129 | public static void throwIfUnchecked(Throwable throwable) { |
| 130 | checkNotNull(throwable); |
| 131 | if (throwable instanceof RuntimeException) { |
| 132 | throw (RuntimeException) throwable; |
| 133 | } |
| 134 | if (throwable instanceof Error) { |
| 135 | throw (Error) throwable; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Propagates {@code throwable} exactly as-is, if and only if it is an instance of {@link |