Walter Bright:

I've thought of allowing "throw new ...", and yours would be in addition to that, in @nogc functions, but was waiting to see how this would play out a bit first.

It's true that currently significant parts of Phobos can't be @nogc, but the solution is not to turn @nogc into its opposite.


See:
https://d.puremagic.com/issues/show_bug.cgi?id=12768


With a comment by monarchdodra:

        static err = new immutable(RangeError)();

I'm surprised this works. If the exception is Immutable,
then how can we chain it? If we catch "Exception", then
we are making something immutable mutable. If we mutate
the exception, then not only do we break the type system,
but it also means the code isn't actually pure:

//----
void foo() pure
{
    static err = new immutable(RangeError)("error");
    throw err;
}

void main()
{
    try
    foo();
    catch(Error e)
    {
        e.msg = "yo!";
    }

    foo(); //[email protected](7): yo!
}

Bye,
bearophile

Reply via email to