generics vs. checked exceptions
John Hendrikx
hjohn at xs4all.nl
Wed Mar 16 20:24:20 UTC 2022
On 16/03/2022 18:36, John Rose wrote:
> All that said, I don’t want to work on it now, because I have far more
> pressing things to get done: pressing in a good, exciting, and
> fruitful way. I imagine Brian has similar feelings.
>
> (Idle question: Does fruitful pressing eventually lead to good
> vintages? One hopes!)
>
> — John
>
> P.S. On one of my many back burners, I’ve been experimenting with
> exposing checked exceptions through Java’s *existing* generics
> (nothing new) to find the limits of what they can do. Here’s a
> snapshot, FWIW, of small number of types which expose not only the
> possible normal result value of an expression, but also its possible
> exceptional result:
>
> http://cr.openjdk.java.net/~jrose/draft/exbox-javadoc
I've been playing with something similar :)
Here is an implementation of Streams which allows checked exceptions
(upto 3) with standard Java:
https://github.com/hjohn/MediaSystem-v2/tree/master/mediasystem-util/src/main/java/hs/mediasystem/util/checked
The test case has readable examples:
https://github.com/hjohn/MediaSystem-v2/blob/master/mediasystem-util/src/test/java/hs/mediasystem/util/checked/CheckedStreamsTest.java
The exceptions are (re)thrown and declared by the terminal operations of
Stream. The lack of a generic type parameter that can indicate a set of
exceptions makes it a bit cumbersome, but it does not cause any problems
when no exceptions are thrown or only runtime exceptions are thrown. In
fact, surprisingly, declaring the same checked exception (through a
generic parameter) several times is seemingly allowed without problem.
--John
More information about the amber-dev
mailing list