Completable Future异常处理runAsync&thenRun

问题描述 投票:0回答:1

假设我有此示例代码,并且在runAsync中遇到异常。我的问题是,此异常会阻止thenRun被执行,因为thenRun在与此代码的调用方方法相同的线程中运行。

private void caller() {
    CompletableFuture.runAsync(() -> {
          try {
              // some code
          } catch (Exception e) {
              throw new CustomException(errorMessage, e);
          }
         }, anInstanceOfTaskExecutor).thenRun(
         // thenRun code
     ));
}

我已经通过this线程,它解释了如何处理异步块引发的异常(即,通过阻塞并使用join)。我想知道如果thenRun CompletableFuture内的代码是否会执行。

假设我有此示例代码,并且在runAsync中遇到异常。我的问题是,此异常是否会阻止thenRun运行,因为thenRun在与...

java exception completable-future
1个回答
0
投票

取决于您要添加completesExceptionally的步骤。

© www.soinside.com 2019 - 2024. All rights reserved.