CompletionStage
如果发生异常,有没有办法返回一个新的?
的 APIexceptionally
似乎不允许您这样做。有没有解决的办法?
基本上我想为这个案子做flatMap
( thenCompose
)exceptionally
public CompletionStage<String> cleanupTask() {
//DO something long running
}
public CompletionStage<String> workThatCanFail() {
//Some long running task that may fail
}
public void action() {
CompletionStage<String> work =
workThatCanFail()
.exceptionally(throwable -> cleanupTask());
}