"case catch" instead of "case throws"?

John Rose john.r.rose at oracle.com
Tue Feb 20 22:49:01 UTC 2024


On 19 Feb 2024, at 10:09, Patrick Doyle wrote:

> This would be the first time where
> "throws" introduces a syntax construct that does not throw the exception in
> question.

Maybe, but it is not the first time that the way an expression produces its result serves as a label of a case.  The syntax of case labels is intentionally similar to the syntax of expressions which could produce values that could match those case labels.  (Similar, not identical.)

Put another way, patterns have a surface syntax which suggests “expressions in reverse”.  If you made a box of a string as /new Box("foo")/ then a matching case label might have a similar syntax /case Box("foo"):/.  So an expression like /throw new Foo()/ might have a matching case label with a similar shape /case throws Foo:/.



More information about the amber-dev mailing list