CompletableFuture已经完成,但有例外 [英] CompletableFuture already completed with an exception
本文介绍了CompletableFuture已经完成,但有例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
CompletableFuture.completedFuture ()返回已使用给定值完成的 CompletedFuture
。
CompletableFuture.completedFuture() returns a CompletedFuture
that is already completed with the given value.
我们如何构建已经异常完成的 CompletableFuture
?
How do we construct a CompletableFuture
that is already completed exceptionally?
意思是,我希望将来抛出一个值,而不是返回一个值例外。
Meaning, instead of returning a value I want the future to throw an exception.
推荐答案
我刚发现这个:
CompletableFuture<T> future = new CompletableFuture<>();
future.completeExceptionally(t);
没有静态工厂方法,但默认构造函数似乎可以完成这项工作。
There is no static factory method, but the default constructor seems to do the job.
这篇关于CompletableFuture已经完成,但有例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文