import java.time.Duration; import java.util.concurrent.StructuredTaskScope; /** The JDK 25/26 timeout exception. In 27 the scope throws ExecutionException with a CancelledByTimeoutException cause. */ public class OldTimeoutException { public static void main(String[] args) throws Exception { try (var scope = StructuredTaskScope.open(StructuredTaskScope.Joiner.awaitAllSuccessfulOrThrow(), cf -> cf.withTimeout(Duration.ofMillis(50)))) { scope.fork(() -> { Thread.sleep(1000); return "late"; }); scope.join(); } catch (StructuredTaskScope.TimeoutException e) { System.out.println("timed out"); } } }