private static void throwAsIOException(Throwable t) throws IOException { Throwables.propagateIfInstanceOf(t, IOException.class); throw new IOException(t); }
@Override public void close() throws IOException { if (closeable != null) { try { closeable.close(); } catch (Exception e) { Throwables.propagateIfInstanceOf(e, IOException.class); throw Throwables.propagate(e); } } } };
/** * Propagates {@code throwable} exactly as-is, if and only if it is an instance of {@link * RuntimeException}, {@link Error}, {@code declaredType1}, or {@code declaredType2}. In the * unlikely case that you have three or more declared checked exception types, you can handle them * all by invoking these methods repeatedly. See usage example in {@link * #propagateIfPossible(Throwable, Class)}. * * @param throwable the Throwable to possibly propagate * @param declaredType1 any checked exception type declared by the calling method * @param declaredType2 any other checked exception type declared by the calling method */ @GwtIncompatible // propagateIfInstanceOf public static <X1 extends Throwable, X2 extends Throwable> void propagateIfPossible( @Nullable Throwable throwable, Class<X1> declaredType1, Class<X2> declaredType2) throws X1, X2 { checkNotNull(declaredType2); propagateIfInstanceOf(throwable, declaredType1); propagateIfPossible(throwable, declaredType2); }
private void delegateToAllChildren(RequestLogLine requestLogLine, RequestLogLineConsumer consumer) throws IOException { Exception exception = null; for (RequestLogger logger : loggers) { try { consumer.accept(logger, requestLogLine); } catch (Exception e) { if (exception == null) { exception = e; } else { exception.addSuppressed(e); } } } if (exception != null) { Throwables.propagateIfInstanceOf(exception, IOException.class); throw Throwables.propagate(exception); } }
public interface CleanupAfterFailure { /** * This is called once {@link Task#perform()} fails. Retrying is stopped once this method throws an exception, * so errors inside this method should be ignored if you don't want to stop retrying. */ void cleanup(); }
/** * Propagates {@code throwable} exactly as-is, if and only if it is an instance of {@link * RuntimeException}, {@link Error}, or {@code declaredType}. Example usage: * * <pre> * try { * someMethodThatCouldThrowAnything(); * } catch (IKnowWhatToDoWithThisException e) { * handle(e); * } catch (Throwable t) { * Throwables.propagateIfPossible(t, OtherException.class); * throw new RuntimeException("unexpected", t); * } * </pre> * * @param throwable the Throwable to possibly propagate * @param declaredType the single checked exception type declared by the calling method */ @GwtIncompatible // propagateIfInstanceOf public static <X extends Throwable> void propagateIfPossible( @Nullable Throwable throwable, Class<X> declaredType) throws X { propagateIfInstanceOf(throwable, declaredType); propagateIfPossible(throwable); }
@Override public void oneDeclared() throws SomeCheckedException { try { methodThatThrowsOtherChecked(); } catch (Throwable t) { Throwables.propagateIfInstanceOf(t, SomeCheckedException.class); throw Throwables.propagate(t); } } };
@Override public void oneDeclared() throws SomeCheckedException { try { methodThatDoesntThrowAnything(); } catch (Throwable t) { Throwables.propagateIfInstanceOf(t, SomeCheckedException.class); throw Throwables.propagate(t); } } };
@Override public void oneDeclared() throws SomeCheckedException { try { methodThatThrowsChecked(); } catch (Throwable t) { Throwables.propagateIfInstanceOf(t, SomeCheckedException.class); throw Throwables.propagate(t); } } };
@Override public void oneDeclared() throws SomeCheckedException { try { methodThatThrowsUnchecked(); } catch (Throwable t) { Throwables.propagateIfInstanceOf(t, SomeCheckedException.class); throw Throwables.propagate(t); } } };
@GwtIncompatible // throwIfInstanceOf public void testPropageIfInstanceOf_null() throws SomeCheckedException { Throwables.propagateIfInstanceOf(null, SomeCheckedException.class); }
/** * Propagates {@code throwable} exactly as-is, if and only if it is an instance of {@link * RuntimeException}, {@link Error}, {@code declaredType1}, or {@code declaredType2}. In the * unlikely case that you have three or more declared checked exception types, you can handle them * all by invoking these methods repeatedly. See usage example in {@link * #propagateIfPossible(Throwable, Class)}. * * @param throwable the Throwable to possibly propagate * @param declaredType1 any checked exception type declared by the calling method * @param declaredType2 any other checked exception type declared by the calling method */ @GwtIncompatible // propagateIfInstanceOf public static <X1 extends Throwable, X2 extends Throwable> void propagateIfPossible( @NullableDecl Throwable throwable, Class<X1> declaredType1, Class<X2> declaredType2) throws X1, X2 { checkNotNull(declaredType2); propagateIfInstanceOf(throwable, declaredType1); propagateIfPossible(throwable, declaredType2); }
@Override public void close() throws IOException { boolean isDone; try { isDone = isDone(); baseYielder.close(); } catch (Throwable t) { // Close on failure try { wrapper.after(false, t); } catch (Exception e) { t.addSuppressed(e); } Throwables.propagateIfInstanceOf(t, IOException.class); throw Throwables.propagate(t); } // "Normal" close try { wrapper.after(isDone, null); } catch (Exception e) { Throwables.propagateIfInstanceOf(e, IOException.class); throw Throwables.propagate(e); } } }
private void pushTaskFile(final File logFile, String taskKey) throws IOException { try { S3Utils.retryS3Operation( () -> { service.putObject(config.getS3Bucket(), taskKey, logFile); return null; } ); } catch (Exception e) { Throwables.propagateIfInstanceOf(e, IOException.class); throw Throwables.propagate(e); } }
/** * Propagates {@code throwable} exactly as-is, if and only if it is an instance of {@link * RuntimeException}, {@link Error}, {@code declaredType1}, or {@code declaredType2}. In the * unlikely case that you have three or more declared checked exception types, you can handle them * all by invoking these methods repeatedly. See usage example in {@link * #propagateIfPossible(Throwable, Class)}. * * @param throwable the Throwable to possibly propagate * @param declaredType1 any checked exception type declared by the calling method * @param declaredType2 any other checked exception type declared by the calling method */ @GwtIncompatible // propagateIfInstanceOf public static <X1 extends Throwable, X2 extends Throwable> void propagateIfPossible( @NullableDecl Throwable throwable, Class<X1> declaredType1, Class<X2> declaredType2) throws X1, X2 { checkNotNull(declaredType2); propagateIfInstanceOf(throwable, declaredType1); propagateIfPossible(throwable, declaredType2); }
/** * Propagates {@code throwable} exactly as-is, if and only if it is an instance of {@link * RuntimeException}, {@link Error}, or {@code declaredType}. Example usage: * * <pre> * try { * someMethodThatCouldThrowAnything(); * } catch (IKnowWhatToDoWithThisException e) { * handle(e); * } catch (Throwable t) { * Throwables.propagateIfPossible(t, OtherException.class); * throw new RuntimeException("unexpected", t); * } * </pre> * * @param throwable the Throwable to possibly propagate * @param declaredType the single checked exception type declared by the calling method */ @GwtIncompatible // propagateIfInstanceOf public static <X extends Throwable> void propagateIfPossible( @NullableDecl Throwable throwable, Class<X> declaredType) throws X { propagateIfInstanceOf(throwable, declaredType); propagateIfPossible(throwable); }
private void closeFromCleaner() { try { if (doClose(false)) { log.error("Entry.close() was not called, closed resources by the JVM"); } } catch (Throwable t) { try { log.error(t, "Error while closing %s", this); } catch (Exception e) { t.addSuppressed(e); } Throwables.propagateIfInstanceOf(t, Error.class); // Must not throw exceptions in the cleaner thread, run by the JVM. } }
/** * To be called by the JVM via {@link Cleaner#clean()}. The only difference from {@link #disposeManually()} is * exception treatment. */ @Override public void run() { if (disposed.compareAndSet(false, true)) { try { doDispose(); // Log statement goes after doDispose(), because logging may fail (e. g. if we are in shutdownHooks). log.error("OffHeapNamespaceExtractionCacheManager.disposeCache() was not called, disposed resources by the JVM"); } catch (Throwable t) { try { log.error(t, "Error while deleting key %s from MapDb", mapDbKey); } catch (Exception e) { t.addSuppressed(e); } Throwables.propagateIfInstanceOf(t, Error.class); // Must not throw exceptions in the cleaner thread, run by the JVM. } } }
Throwables.propagateIfInstanceOf(e, AmazonServiceException.class); Throwables.propagateIfInstanceOf(e, SegmentLoadingException.class); throw Throwables.propagate(e);
return getUninterruptibly(waiter, timeout, unit); } catch (ExecutionException e) { propagateIfInstanceOf(e.getCause(), ExecutionException.class); propagateIfInstanceOf(e.getCause(), CancellationException.class); throw failureWithCause(e, "Unexpected exception"); } finally {