Why does `ScopedValue.where(SCOPE_VALUE, val).call()` throw Exception?

Josiah Noel josiahnoel at gmail.com
Thu Mar 23 17:39:21 UTC 2023


I guess to me it's not apparent that an operation that uses a scoped value
must necessarily throw a checked exception that must be handled.

On Thu, Mar 23, 2023, 12:31 PM Andrew Haley <aph-open at littlepinkcloud.com>
wrote:

> On 3/23/23 11:16, Kasper Nielsen wrote:
> > I'm in a similar situation as Josiah.
> >
> > It was the first thing I noticed when using ScopedValue.
> > Why do I have to handle an exception when the code I'm calling
> > does not throw any checked exceptions?
> >
> > So I would really like something like
> >   <R> R supply(Supplier<? extends R> op);
> > on ScopedValue.Carrier
> >
> > and maybe rearrange Carrier to
> > void where(ScopedValue<T> key, T value, Runnable op);
> > R where(ScopedValue<T> key, T value, Supplier<? extends R> op);
>
> A function from Exception -> R is more useful than a plain Supplier
> because the handler might need to know what kind of Exception was
> thrown.
>
> > R whereChecked(ScopedValue<T> key, T value, Callable<? extends R> op)
> throws Exception;
>
> --
> Andrew Haley  (he/him)
> Java Platform Lead Engineer
> Red Hat UK Ltd. <https://www.redhat.com>
> https://keybase.io/andrewhaley
> EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/loom-dev/attachments/20230323/7d83d9ac/attachment-0001.htm>


More information about the loom-dev mailing list