package bunny.async; import java.util.concurrent.CompletableFuture; public class CompletableFutureTest7 { public static void main(String[] args) { CompletableFuture future = CompletableFuture.supplyAsync(() -> { // 模拟一个抛出异常的任务 throw new RuntimeException("Task failed"); }); CompletableFuture handledFuture = future.exceptionally(ex -> { System.out.println("Exception 消息是什么呢?: " + ex.getMessage()); return 0; }); int result = handledFuture.join(); System.out.println("Result: " + result); } }