private void wrapAndThrowRuntimeExecutionExceptionOrError(Throwable cause) { if (cause instanceof Error) { throw new ExecutionError((Error) cause); } else { throw new UncheckedExecutionException(cause); } }
@Override public void runWithTimeout(Runnable runnable, long timeoutDuration, TimeUnit timeoutUnit) { checkNotNull(runnable); checkNotNull(timeoutUnit); try { runnable.run(); } catch (RuntimeException e) { throw new UncheckedExecutionException(e); } catch (Error e) { throw new ExecutionError(e); } catch (Throwable e) { // It's a non-Error, non-Exception Throwable. Such classes are usually intended to extend // Exception, so we'll treat it like a RuntimeException. throw new UncheckedExecutionException(e); } }
@Override public V getUnchecked(K key) { try { return get(key); } catch (ExecutionException e) { throw new UncheckedExecutionException(e.getCause()); } }
private static void wrapAndThrowUnchecked(Throwable cause) { if (cause instanceof Error) { throw new ExecutionError((Error) cause); } /* * It's an Exception. (Or it's a non-Error, non-Exception Throwable. From my survey of such * classes, I believe that most users intended to extend Exception, so we'll treat it like an * Exception.) */ throw new UncheckedExecutionException(cause); }
private void wrapAndThrowExecutionExceptionOrError(Throwable cause) throws ExecutionException { if (cause instanceof Error) { throw new ExecutionError((Error) cause); } else if (cause instanceof RuntimeException) { throw new UncheckedExecutionException(cause); } else { throw new ExecutionException(cause); } }
@Override public V getUnchecked(K key) { try { return get(key); } catch (ExecutionException e) { throw new UncheckedExecutionException(e.getCause()); } }
@Override public <T> T callWithTimeout(Callable<T> callable, long timeoutDuration, TimeUnit timeoutUnit) throws ExecutionException { checkNotNull(callable); checkNotNull(timeoutUnit); try { return callable.call(); } catch (RuntimeException e) { throw new UncheckedExecutionException(e); } catch (Exception e) { throw new ExecutionException(e); } catch (Error e) { throw new ExecutionError(e); } catch (Throwable e) { // It's a non-Error, non-Exception Throwable. Such classes are usually intended to extend // Exception, so we'll treat it like an Exception. throw new ExecutionException(e); } }
@Override public void runWithTimeout(Runnable runnable, long timeoutDuration, TimeUnit timeoutUnit) { checkNotNull(runnable); checkNotNull(timeoutUnit); try { runnable.run(); } catch (RuntimeException e) { throw new UncheckedExecutionException(e); } catch (Error e) { throw new ExecutionError(e); } catch (Throwable e) { // It's a non-Error, non-Exception Throwable. Such classes are usually intended to extend // Exception, so we'll treat it like a RuntimeException. throw new UncheckedExecutionException(e); } }
@Override public V getUnchecked(K key) { try { return get(key); } catch (ExecutionException e) { throw new UncheckedExecutionException(e.getCause()); } }
private void wrapAndThrowRuntimeExecutionExceptionOrError(Throwable cause) { if (cause instanceof Error) { throw new ExecutionError((Error) cause); } else { throw new UncheckedExecutionException(cause); } }
private static void wrapAndThrowUnchecked(Throwable cause) { if (cause instanceof Error) { throw new ExecutionError((Error) cause); } /* * It's an Exception. (Or it's a non-Error, non-Exception Throwable. From my survey of such * classes, I believe that most users intended to extend Exception, so we'll treat it like an * Exception.) */ throw new UncheckedExecutionException(cause); }
private void wrapAndThrowExecutionExceptionOrError(Throwable cause) throws ExecutionException { if (cause instanceof Error) { throw new ExecutionError((Error) cause); } else if (cause instanceof RuntimeException) { throw new UncheckedExecutionException(cause); } else { throw new ExecutionException(cause); } }
@Override public V getUnchecked(K key) { try { return get(key); } catch (ExecutionException e) { throw new UncheckedExecutionException(e.getCause()); } }
private static <X extends Exception> void wrapAndThrowExceptionOrError( Throwable cause, Class<X> exceptionClass) throws X { if (cause instanceof Error) { throw new ExecutionError((Error) cause); } if (cause instanceof RuntimeException) { throw new UncheckedExecutionException(cause); } throw newWithCause(exceptionClass, cause); }
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); } }
@Override @SuppressWarnings({"PMD.PreserveStackTrace", "PMD.AvoidCatchingNPE", "NullAway"}) public V getUnchecked(K key) { try { return cache.get(key); } catch (NullPointerException | InvalidCacheLoadException e) { throw e; } catch (CacheLoaderException e) { throw new UncheckedExecutionException(e.getCause()); } catch (Exception e) { throw new UncheckedExecutionException(e); } catch (Error e) { throw new ExecutionError(e); } }
private static <X extends Exception> void wrapAndThrowExceptionOrError( Throwable cause, Class<X> exceptionClass) throws X { if (cause instanceof Error) { throw new ExecutionError((Error) cause); } if (cause instanceof RuntimeException) { throw new UncheckedExecutionException(cause); } throw newWithCause(exceptionClass, cause); }
@Override @SuppressWarnings({"PMD.PreserveStackTrace", "NullAway"}) public V get(K key) throws ExecutionException { requireNonNull(key); try { return cache.get(key); } catch (InvalidCacheLoadException e) { throw e; } catch (CacheLoaderException e) { throw new ExecutionException(e.getCause()); } catch (RuntimeException e) { throw new UncheckedExecutionException(e); } catch (Error e) { throw new ExecutionError(e); } }
throw new ExecutionError((Error) cause); } else if (cause instanceof RuntimeException) { throw new UncheckedExecutionException(cause);
public void testBulkLoadingExceptionWithCause() { final Exception cause = new Exception(); final UncheckedExecutionException uee = new UncheckedExecutionException(cause); final ExecutionException ee = new ExecutionException(cause); LoadingCache<Object, Object> cacheUnchecked = CacheBuilder.newBuilder().build(bulkLoader(exceptionLoader(uee))); LoadingCache<Object, Object> cacheChecked = CacheBuilder.newBuilder().build(bulkLoader(exceptionLoader(ee))); try { cacheUnchecked.getAll(asList(new Object())); fail(); } catch (ExecutionException e) { fail(); } catch (UncheckedExecutionException caughtEe) { assertThat(caughtEe).hasCauseThat().isSameAs(uee); } try { cacheChecked.getAll(asList(new Object())); fail(); } catch (ExecutionException caughtEe) { assertThat(caughtEe).hasCauseThat().isSameAs(ee); } }