Why is SwitchError an error and how is it unsafe to continue after catching it?

Dennis dkorpel at gmail.com
Sun Feb 24 12:42:32 UTC 2019


On Sunday, 24 February 2019 at 10:53:09 UTC, aliak wrote:
> But the following code is very recoverable and I don't see how 
> it's unsafe to continue executing:

There is no guarantee that a final switch throws an Error. From 
what I've heard of Walter [1] (though I can't find it in the 
spec), the default case in a final switch is assumed to be 
unreachable, so in optimized (non-safe release) code you might 
just go out of bounds of the jump table and execute garbage code 
instead of catching and Error, which is only a debug facility.

[1] https://issues.dlang.org/show_bug.cgi?id=13169


More information about the Digitalmars-d-learn mailing list