STS allows to bypass any checked exceptions
Attila Kelemen
attila.kelemen85 at gmail.com
Sun May 14 10:58:00 UTC 2023
> The current spec is that handleComplete is not invoked after the scope
> has been shutdown. Calling shutdown means you've got the outcome,
> interrupt the unfinished tasks as you don't care about them. Aside from
> logging, what would your code do? The equivalent with Executors and
> Future.cancel is Future::get throwing CancellationException - any
> logging needs to be in the task.
Mostly it would be logged, but my issue is a little bit more than
that. Consider the following (non-STS) code:
```
try (var resource = create()) {
doSomething(resource);
}
```
Suppose `resource.close()` fails with an exception, because of a
cleanup error (say temporary files remain somewhere). In this case,
the whole call fails with an exception, which is the conservative
thing to do. In fact, even is `doSomething` fails as well, the
exception in `close` will not be hidden (too bad `finally` was not
written like this).
However, STS creates a trap, because if you forget to handle the
exception thrown by the task (basically - as is now - it is forcing
you to put everything into a try-catch in each task, otherwise you are
just being hopeful), then likely nobody will notice the problem until
many cleanup issues accumulate and blow up in your face.
More information about the loom-dev
mailing list