Question about Pattern-Matching for Switch

David Alayachew davidalayachew at gmail.com
Sun Jun 2 02:57:29 UTC 2024


Hello Amber Dev,

Apologies for not having tested many features lately for this project (and
others). Juggling insane workloads at work.

Today is the first day I had a moment to breath in months, so I tried out
some stuff, and I was confused.

I have a Switch Expression where the input is a Sealed Type. For this
particular Switch Expression, almost every branch of it is going to throw
an Exception of some sort. I added all of the failure cases to the Switch
Expression, pressed compile, and it threw the following compilation error.

> InputFormat.java:161: error: switch expression does not have any result
expressions
>                   switch (next)

Again, there is going to be one result expression, so I am not blocked by
this compilation error.

I was just really surprised to see an intentional road block there.

Why is there a compilation error if all of the arms of a Switch Expression
are just throwing Exceptions?

Thank you for your time and help!
David Alayachew
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20240601/75082c21/attachment.htm>


More information about the amber-dev mailing list