On Wednesday, 16 April 2014 at 19:53:01 UTC, bearophile wrote:
Peter Alexander:

* Does @nogc => nothrow? If I'm not mistaken, throw must through a GC-allocated Throwable.

* If the above is true, does that mean exceptions cannot be used at all in @nogc code?

This should work:

void foo() @nogc nothrow {
    static const err = new Error("error");
    throw err;
}

Bye,
bearophile

(I assume that nothrow isn't meant to be there?)

What if the exception needs information about the error?

You could do something like this:

void foo() @nogc
{
    static err = new Error();
    if (badthing)
    {
        err.setError("badthing happened");
        throw err;
    }
}

However, that raises a second question: since err is allocated when a new thread is created, does that mean @nogc functions cannot create threads in the presence of such static initialisation?

Reply via email to