Exception handling in switch (Preview)

Guy Steele guy.steele at oracle.com
Thu Apr 25 03:06:48 UTC 2024



On Apr 24, 2024, at 10:50 PM, Kevin Bourrillion <kevinb9n at gmail.com> wrote:

Hey Angelos!

For whatever my take is worth here, I'm also skeptical. I think the bar for adding another way to catch exceptions should be really high, and the benefits here wouldn't clear it. I just don't expect the nested switch-in-try will be painful enough often enough.

This feature would only be applicable when the whole possibly-exception-producing code can fit into a single expression in the switch header . . .

This raises a very good question: what do we expect the "whole possibly-exception-producing code” to look like in practice?

I conjecture that the attractive situation for using switch-with-“case throws"-clauses will NOT involve arbitrarily large expressions that might need to be refactored, but rather a single method call (or possibly an expression with a single operator) where all argument expressions are variables or constants, rather than other stuff that might cause exceptions.

But I am not sure. So maybe this is a conjecture that could be researched.

—Guy

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-spec-observers/attachments/20240425/edc3e52b/attachment-0003.htm>


More information about the amber-spec-observers mailing list