Why is SwitchError an error and how is it unsafe to continue after catching it?
aliak
something at something.com
Mon Feb 25 12:59:21 UTC 2019
On Sunday, 24 February 2019 at 11:05:31 UTC, Alex wrote:
> On Sunday, 24 February 2019 at 10:53:09 UTC, aliak wrote:
>> [...]
>
> There is a semantic difference between a switch and a final
> switch statement, defined here:
> https://dlang.org/spec/statement.html#final-switch-statement
>
> By this difference, the writer of the final switch declares,
> that it is unrecoverable to pass something unexpected to the
> switch statement. The catch of an error as you demonstrated is,
> therefore, a contradiction to the finality of the switch.
Hmm ok. Yes that makes sense to see it that way. Thanks!
>
> I mean, if you know, that something beyond the enum can be
> passed, use a normal switch and handle the case in the default
> section. If you are able to ensure, this case is unreachable,
> you express this knowledge/ability by the final switch and
> don't need the try-catch clause at all.
Aye, agreed.
More information about the Digitalmars-d-learn
mailing list