@Override public void run() { try { wrapped.call(); } catch (Exception e) { throwIfUnchecked(e); throw new RuntimeException(e); } } };
private Object invokeGeneratorMethod(Method generator, Object... args) { try { return generator.invoke(this, args); } catch (InvocationTargetException e) { throwIfUnchecked(e.getCause()); throw new RuntimeException(e.getCause()); } catch (Exception e) { throwIfUnchecked(e); throw new RuntimeException(e); } }
/** Returns the most concrete public methods from {@code type}. */ private static Method[] getMostConcreteMethods(Class<?> type) { Method[] methods = type.getMethods(); for (int i = 0; i < methods.length; i++) { try { methods[i] = type.getMethod(methods[i].getName(), methods[i].getParameterTypes()); } catch (Exception e) { throwIfUnchecked(e); throw new RuntimeException(e); } } return methods; }
private void throwIfFailed() { Throwable t = failure.get(); if (t != null) { throwIfUnchecked(t); throw new RuntimeException(t); } }
private static void closeUnchecked(AutoCloseable closeable) { try { closeable.close(); } catch (Exception e) { throwIfUnchecked(e); throw new RuntimeException(e); } }
private static RuntimeException propagate(Throwable throwable) { if (throwable instanceof InterruptedException) { Thread.currentThread().interrupt(); } throwIfUnchecked(throwable); throw new RuntimeException(throwable); } }
private static RuntimeException propagate(Throwable throwable) { if (throwable instanceof InterruptedException) { Thread.currentThread().interrupt(); } throwIfUnchecked(throwable); throw new RuntimeException(throwable); } }
@Override public void run() { try { wrapped.call(); } catch (Exception e) { throwIfUnchecked(e); throw new RuntimeException(e); } } };
public Runnable embedVersion(Runnable runnable) { requireNonNull(runnable, "runnable is null"); try { return (Runnable) runnableConstructor.invoke(runnable); } catch (Throwable throwable) { throwIfUnchecked(throwable); throw new RuntimeException(throwable); } } }
private static <T> T doAs(Subject subject, GssSupplier<T> action) throws GSSException { try { return Subject.doAs(subject, (PrivilegedExceptionAction<T>) action::get); } catch (PrivilegedActionException e) { Throwable t = e.getCause(); throwIfInstanceOf(t, GSSException.class); throwIfUnchecked(t); throw new RuntimeException(t); } }
doTestNulls(cls, Visibility.PACKAGE); } catch (Exception e) { throwIfUnchecked(e); throw new RuntimeException(e);
@Override public Type getType(TypeSignature signature) { Type type = types.get(signature); if (type == null) { try { return parametricTypeCache.getUnchecked(signature); } catch (UncheckedExecutionException e) { throwIfUnchecked(e.getCause()); throw new RuntimeException(e.getCause()); } } return type; }
/** * Propagates {@code throwable} exactly as-is, if and only if it is an instance of {@link * RuntimeException} or {@link Error}. Example usage: * * <pre> * try { * someMethodThatCouldThrowAnything(); * } catch (IKnowWhatToDoWithThisException e) { * handle(e); * } catch (Throwable t) { * Throwables.propagateIfPossible(t); * throw new RuntimeException("unexpected", t); * } * </pre> * * @deprecated Use {@link #throwIfUnchecked}, which has the same behavior but rejects {@code * null}. */ @Deprecated @GwtIncompatible public static void propagateIfPossible(@Nullable Throwable throwable) { if (throwable != null) { throwIfUnchecked(throwable); } }
public void testThrowIfUnchecked_null() throws SomeCheckedException { try { throwIfUnchecked(null); fail(); } catch (NullPointerException expected) { } }
@SuppressWarnings("ThrowIfUncheckedKnownChecked") public void testThrowIfUnchecked_Checked() { throwIfUnchecked(new SomeCheckedException()); }
private static <K, V> Map<K, V> getAll(LoadingCache<K, V> cache, Iterable<K> keys) { try { return cache.getAll(keys); } catch (ExecutionException | UncheckedExecutionException e) { throwIfInstanceOf(e.getCause(), PrestoException.class); throwIfUnchecked(e); throw new UncheckedExecutionException(e); } }
/** Force the random seed to a predictable value. */ public static void ensureRandomSeed(FrequencySketch<?> sketch) { try { Field field = FrequencySketch.class.getDeclaredField("randomSeed"); field.setAccessible(true); field.setInt(sketch, RANDOM_SEED); } catch (Exception e) { Throwables.throwIfUnchecked(e); throw new RuntimeException(e); } } }
public void testThrowIfUnchecked_Error() { try { throwIfUnchecked(new SomeError()); fail(); } catch (SomeError expected) { } }
public void testThrowIfUnchecked_Unchecked() { try { throwIfUnchecked(new SomeUncheckedException()); fail(); } catch (SomeUncheckedException expected) { } }
public static List<Page> toPages(OperatorFactory operatorFactory, DriverContext driverContext, List<Page> input) { try (Operator operator = operatorFactory.createOperator(driverContext)) { return toPages(operator, input.iterator()); } catch (Exception e) { throwIfUnchecked(e); throw new RuntimeException(e); } }