STS allows to bypass any checked exceptions
Remi Forax
forax at univ-mlv.fr
Sat May 13 21:33:24 UTC 2023
The more I think about the way STS/TaskHandle manages checked exceptions the less I like it.
Here is my problem:
Do you agree that this code is kind of awful ?
static <T> T bypassCheckedException(Callable<? extends T> callable) {
try {
return callable.call();
} catch (Exception e) {
throw new IllegalStateException("task complete with exception");
}
}
so why this other one is not
static <T> T bypassCheckedException(Callable<? extends T> callable) {
try(var sts = new StructuredTaskScope<>()) {
var task = sts.fork(callable);
try {
sts.join();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
return task.get();
}
}
given that it has exactly the same semantics ?
regards,
Rémi
More information about the loom-dev
mailing list