== Quote from Timon Gehr ([email protected])'s article
> On 09/13/2011 12:27 AM, Iain Buclaw wrote:
> > I have been merging Phobos that got released with the latest DMD release 
> > into
> > GDC. And couldn't help but notice this nostalgic error I implemented a 
> > while back:
> >
> >      std/format.d:1520: Error: cannot goto into catch block
> >
> >
> > Line of concern in phobos:
> > https://github.com/D-Programming-Language/phobos/blob/master/std/format.d#L1539
> >
> > Part of spec which error implements:
> > http://www.digitalmars.com/d/2.0/statement.html#GotoStatement
> Where does it say that a goto into a catch block is categorically
> banned? It only says that a goto cannot skip a variable initialization.

Which it does in this situation (what is initialising UtfException e?).

> catch(Type){}
> and
> catch{}
> are valid forms too. Neither one contains a declaration.
> Sure, usually a goto into a catch block means that someone is abusing
> exceptions for regular control flow, but if you just want a quick and
> dirty hack, or if a third-party API forces you to, I don't think the
> language should stand in your way.


In terms of codegen for such, you will still pass through any cleanup that was
generated when the catch block ends (ie: builtin unwind routines).

Think of your latter example as being rewritten as:

try
{
    // questionable user code
}
catch
{
    try
    {
        // user catch code
    }
    finally
    {
        // compiler generated clean-up block
    }
}


Regards
Iain

Reply via email to