Expression switch exception naming
Gavin Bierman
gavin.bierman at oracle.com
Wed Mar 28 13:15:33 UTC 2018
Dear experts,
We're busy putting the finishing touches to the spec for expression switches. Here's one issue that came up that we'd like your opinion on.
Here is a part of the spec that deals with the dynamic semantics of expression switch
- If no pattern matches and there is no `default` pattern label, then
a **??** is thrown and the entire expression `switch` completes abruptly for that reason.
So, the question is: What shall we call the **??** exception? There are two ways of looking at this:
1. The VM-centric view. Because the compiler checked that the expression switch was exhaustive, this can only have happened because someone has changed something after compilation. Right now that would be because we have added a new enum constant. In this case we could perhaps raise an "EnumConstantNotPresentException" exception. But we are planning to introduce sealed types in a future version, and we could run into a similar error, where clearly the exception name can't refer to an enum. We need something that covers all possible causes. Accordingly, we could go with something like "IncompatibleClassChangeException". Whilst accurate, one might fear that the average Java programmer will not find this an informative exception name.
2. The language-centric view. We should name this exception after the feature that has caused it to be raised. So "MatchFailureException", "PatternFailureException", "UnexpectedMatchException" might be possibilities. A worry here might be that other future features might want to raise this exception, and the name will be less applicable. Perhaps "UnexpectedValueException"?
Your thoughts/suggestions much appreciated!
Gavin
More information about the amber-spec-experts
mailing list