假设我有此示例代码,并且在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在与...
取决于您要添加completesExceptionally
的步骤。