Is anything being done about exceptions & nogc?

w0rp via Digitalmars-d digitalmars-d at puremagic.com
Fri Apr 10 05:29:59 PDT 2015


On Friday, 10 April 2015 at 03:13:53 UTC, weaselcat wrote:
> Hi,
> the biggest blocker to converting a _lot_ of code to @nogc is 
> exceptions.
> Has there been anything proposed to help alleviate this? I 
> couldn't find anything.
>
> thanks.

One thing that can be done now at least is that allocating 
exceptions statically. So the stack trace will be off by one line 
and you can't pass in any runtime values to the exception, 
realisitcally, but you can use them in a @nogc function.

@nogc
void foo (bool value) {
     if (value) {
         static immutable exception = new Exception("message");
         throw exception;
     }
}

@nogc
void main(string[] argv) {
     foo(false); // fine
     foo(true); // throws
}

Passing exceptions by value, or via reference counting, would 
solve exceptions without garbage collection more generally.


More information about the Digitalmars-d mailing list