/** * Converts a {@link ThrowingRunnable} into a {@link Runnable} which throws all checked exceptions * as unchecked. * * @param throwingRunnable to convert into a {@link Runnable} * @return {@link Runnable} which throws all checked exceptions as unchecked. */ static Runnable unchecked(ThrowingRunnable<?> throwingRunnable) { return () -> { try { throwingRunnable.run(); } catch (Throwable t) { ExceptionUtils.rethrow(t); } }; } }
/** * Convert a {@link BiConsumerWithException} into a {@link BiConsumer}. * * @param biConsumerWithException BiConsumer with exception to convert into a {@link BiConsumer}. * @param <A> first input type * @param <B> second input type * @return {@link BiConsumer} which rethrows all checked exceptions as unchecked. */ static <A, B> BiConsumer<A, B> unchecked(BiConsumerWithException<A, B, ?> biConsumerWithException) { return (A a, B b) -> { try { biConsumerWithException.accept(a, b); } catch (Throwable t) { ExceptionUtils.rethrow(t); } }; } }
/** * Convert at {@link FunctionWithException} into a {@link Function}. * * @param functionWithException function with exception to convert into a function * @param <A> input type * @param <B> output type * @return {@link Function} which throws all checked exception as an unchecked exception. */ public static <A, B> Function<A, B> uncheckedFunction(FunctionWithException<A, B, ?> functionWithException) { return (A value) -> { try { return functionWithException.apply(value); } catch (Throwable t) { ExceptionUtils.rethrow(t); // we need this to appease the compiler :-( return null; } }; }
/** * Converts a {@link ThrowingConsumer} into a {@link Consumer} which throws checked exceptions * as unchecked. * * @param throwingConsumer to convert into a {@link Consumer} * @param <A> input type * @return {@link Consumer} which throws all checked exceptions as unchecked */ public static <A> Consumer<A> uncheckedConsumer(ThrowingConsumer<A, ?> throwingConsumer) { return (A value) -> { try { throwingConsumer.accept(value); } catch (Throwable t) { ExceptionUtils.rethrow(t); } }; } }
/** * Convert at {@link BiFunctionWithException} into a {@link BiFunction}. * * @param biFunctionWithException function with exception to convert into a function * @param <A> input type * @param <B> output type * @return {@link BiFunction} which throws all checked exception as an unchecked exception. */ static <A, B, C> BiFunction<A, B, C> unchecked(BiFunctionWithException<A, B, C, ?> biFunctionWithException) { return (A a, B b) -> { try { return biFunctionWithException.apply(a, b); } catch (Throwable t) { ExceptionUtils.rethrow(t); // we need this to appease the compiler :-( return null; } }; } }
public static void suppressExceptions(RunnableWithException action) { try { action.run(); } catch (InterruptedException e) { // restore interrupted state Thread.currentThread().interrupt(); } catch (Throwable t) { if (isJvmFatalError(t)) { rethrow(t); } } }
@Override public void execute(Runnable command) { // To not block interrupts here (faster cancellation) we acquire interruptibly. // Unfortunately, we need to rethrow this as a RuntimeException (suboptimal), because // the method signature does not permit anything else, and we want to maintain the // Executor interface for transparent drop-in. try { permits.acquire(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new FlinkRuntimeException("interrupted:", e); } final SemaphoreReleasingRunnable runnable = new SemaphoreReleasingRunnable(command, permits); try { delegate.execute(runnable); } catch (Throwable e) { runnable.release(); ExceptionUtils.rethrow(e, e.getMessage()); } }
default R apply(T t, U u) { try { return applyWithException(t, u); } catch (Throwable e) { ExceptionUtils.rethrow(e); // we have to return a value to please the compiler // but we will never reach the code here return null; } } }
@Override default void accept(T t, U u) { try { acceptWithException(t, u); } catch (Throwable e) { ExceptionUtils.rethrow(e); } } }
/** * Converts a {@link ThrowingConsumer} into a {@link Consumer} which throws checked exceptions * as unchecked. * * @param throwingConsumer to convert into a {@link Consumer} * @param <A> input type * @return {@link Consumer} which throws all checked exceptions as unchecked */ public static <A> Consumer<A> uncheckedConsumer(ThrowingConsumer<A, ?> throwingConsumer) { return (A value) -> { try { throwingConsumer.accept(value); } catch (Throwable t) { ExceptionUtils.rethrow(t); } }; } }
/** * Converts a {@link ThrowingRunnable} into a {@link Runnable} which throws all checked exceptions * as unchecked. * * @param throwingRunnable to convert into a {@link Runnable} * @return {@link Runnable} which throws all checked exceptions as unchecked. */ static Runnable unchecked(ThrowingRunnable<?> throwingRunnable) { return () -> { try { throwingRunnable.run(); } catch (Throwable t) { ExceptionUtils.rethrow(t); } }; } }
/** * Convert at {@link FunctionWithException} into a {@link Function}. * * @param functionWithException function with exception to convert into a function * @param <A> input type * @param <B> output type * @return {@link Function} which throws all checked exception as an unchecked exception. */ public static <A, B> Function<A, B> uncheckedFunction(FunctionWithException<A, B, ?> functionWithException) { return (A value) -> { try { return functionWithException.apply(value); } catch (Throwable t) { ExceptionUtils.rethrow(t); // we need this to appease the compiler :-( return null; } }; }
/** * Convert a {@link BiConsumerWithException} into a {@link BiConsumer}. * * @param biConsumerWithException BiConsumer with exception to convert into a {@link BiConsumer}. * @param <A> first input type * @param <B> second input type * @return {@link BiConsumer} which rethrows all checked exceptions as unchecked. */ static <A, B> BiConsumer<A, B> unchecked(BiConsumerWithException<A, B, ?> biConsumerWithException) { return (A a, B b) -> { try { biConsumerWithException.accept(a, b); } catch (Throwable t) { ExceptionUtils.rethrow(t); } }; } }
public static void suppressExceptions(RunnableWithException action) { try { action.run(); } catch (InterruptedException e) { // restore interrupted state Thread.currentThread().interrupt(); } catch (Throwable t) { if (isJvmFatalError(t)) { rethrow(t); } } }
@Override public void notifyBufferPoolOwnerReleased() { checkState(owner != null, "The buffer owner should not be null."); try { networkBufferPool.destroyBufferPool(this); } catch (IOException e) { ExceptionUtils.rethrow(e); } }
public static void suppressExceptions(RunnableWithException action) { try { action.run(); } catch (InterruptedException e) { // restore interrupted state Thread.currentThread().interrupt(); } catch (Throwable t) { if (isJvmFatalError(t)) { rethrow(t); } } }
public CompletedCheckpoint finalizeCheckpointNonExternalized() { synchronized (lock) { checkState(isFullyAcknowledged(), "Pending checkpoint has not been fully acknowledged yet."); // make sure we fulfill the promise with an exception if something fails try { // finalize without external metadata return finalizeInternal(null, null); } catch (Throwable t) { onCompletionPromise.completeExceptionally(t); ExceptionUtils.rethrow(t); return null; // silence the compiler } } }
private void shutDownInternally() throws Exception { Exception exception = null; synchronized (lock) { try { resourceManager.shutDown(); } catch (Exception e) { exception = ExceptionUtils.firstOrSuppressed(e, exception); } try { resourceManagerRuntimeServices.shutDown(); } catch (Exception e) { exception = ExceptionUtils.firstOrSuppressed(e, exception); } if (exception != null) { ExceptionUtils.rethrow(exception, "Error while shutting down the resource manager runner."); } } }
@Override protected void initChannel(SocketChannel socketChannel) { try { // SSL should be the first handler in the pipeline if (sslHandlerFactory != null) { socketChannel.pipeline().addLast("ssl", sslHandlerFactory.createNettySSLHandler()); } socketChannel.pipeline() .addLast(new HttpClientCodec()) .addLast(new HttpObjectAggregator(configuration.getMaxContentLength())) .addLast(new ChunkedWriteHandler()) // required for multipart-requests .addLast(new IdleStateHandler(configuration.getIdlenessTimeout(), configuration.getIdlenessTimeout(), configuration.getIdlenessTimeout(), TimeUnit.MILLISECONDS)) .addLast(new ClientHandler()); } catch (Throwable t) { t.printStackTrace(); ExceptionUtils.rethrow(t); } } };
@Override protected void initChannel(SocketChannel socketChannel) { try { // SSL should be the first handler in the pipeline if (sslHandlerFactory != null) { socketChannel.pipeline().addLast("ssl", sslHandlerFactory.createNettySSLHandler()); } socketChannel.pipeline() .addLast(new HttpClientCodec()) .addLast(new HttpObjectAggregator(configuration.getMaxContentLength())) .addLast(new ChunkedWriteHandler()) // required for multipart-requests .addLast(new IdleStateHandler(configuration.getIdlenessTimeout(), configuration.getIdlenessTimeout(), configuration.getIdlenessTimeout(), TimeUnit.MILLISECONDS)) .addLast(new ClientHandler()); } catch (Throwable t) { t.printStackTrace(); ExceptionUtils.rethrow(t); } } };