Consensus on goto's into catch blocks

Iain Buclaw ibuclaw at ubuntu.com
Thu Jun 13 13:48:42 PDT 2013


On 13 June 2013 20:08, monarch_dodra <monarchdodra at gmail.com> wrote:
> On Thursday, 13 June 2013 at 18:51:01 UTC, Brad Roberts wrote:
>>
>> On 6/13/13 10:35 AM, Iain Buclaw wrote:
>>
>> I think it should be illegal, but not because it's a catch block but
>> because of the initialization.
>>  If the catch was just "catch (Exception)" then it shouldn't be illegal.
>
>
> Again for what it's worth, the C++ program with "catch(...)" also fails.
>
> Even if the variable is unnamed though, doesn't the code still cross the
> declaration, which is enough to make a mess of things? I mean, the caught
> exception is still on the stack somewhere, right?
>
> And still, if, by some hoops, we could make it work, do we really want to
> add that functionality? I mean, would it really even be useful?
>
> That, and I'm not a fan to having code that breaks just because you later
> decided to name a variable.
>
> Eg:
> before:
> catch(Exception) //OK
> after
> catch(Exception e) //Nope, that's illegal now. Good luck finding out why!


Well, a good error message will do well in that case.

Currently, gdc has the following stock errors:

    "cannot goto into catch block"

Which is indeed confusing if anonymous catches are allowed to bypass
this check.  What I would instead do (once I have the scan for skipped
initialisations complete) is have a more meaningful, and generic:

    "goto to label 'L2' skips initialisation of 'Exception e'"


Ditto for any other forms of jumps over any other local variable declarations.


Regards
--
Iain Buclaw

*(p < e ? p++ : p) = (c & 0x0f) + '0';


More information about the Digitalmars-d mailing list