只是浏览CompletableFuture
文档并偶然发现了completeExceptionally
和obtrudeException
方法,并且很难理解差异和用例。社区可以通过示例帮助了解差异和用例吗?
问问题
333 次
2 回答
2
于 2021-09-04T12:23:27.547 回答
0
完全异常:
completableFuture.completeExceptionally(
new RuntimeException("Calculation failed!"));
//..
completableFuture.get(); //exception will be thrown whether `completableFuture` was not already completed.
突出异常:
completableFuture.obtrudeException(
new RuntimeException("Calculation failed!"));
//..
completableFuture.get(); //exception will be thrown **whether or not** `completableFuture` was completed.
于 2021-09-04T12:06:20.703 回答