STS allows to bypass any checked exceptions
Attila Kelemen
attila.kelemen85 at gmail.com
Sat May 13 22:24:02 UTC 2023
Also, another issue is that, if I shutdown the STS, then every
exception happening will be silently discarded with no means to see
them. Even though the action can have bugs in case of shutdown. For
example, it can run into an NPE or whatever in a mismanaged cleanup.
This is, because currently STS does this while running the task:
```
T result = null;
Throwable ex = null;
try {
result = task.call();
} catch (Throwable e) {
ex = e;
}
// invoke handleComplete if the scope has not shutdown
if (!scope.isShutdown()) {
// ... omitted handleComplete logic
}
```
Remi Forax <forax at univ-mlv.fr> ezt írta (időpont: 2023. máj. 13., Szo, 23:39):
>
> 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