1

只是浏览CompletableFuture文档并偶然发现了completeExceptionallyobtrudeException方法,并且很难理解差异和用例。社区可以通过示例帮助了解差异和用例吗?

4

2 回答 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 回答