Proposal 2: Exceptions and @nogc

Dukc via Digitalmars-d digitalmars-d at puremagic.com
Sun Apr 9 23:17:43 PDT 2017


On Monday, 10 April 2017 at 02:04:35 UTC, Andrew Godfrey wrote:
> On Monday, 10 April 2017 at 01:54:54 UTC, Walter Bright wrote:
>>    throw new E(string);
>
> Did you mean to use the "scope" keyword somewhere in the line 
> above?

No. In the scope the exceptions are instantiated they are not 
scoped. He meant that if, and only if, they are instantiated in 
the way mentioned above they are reference counted. If an 
exception is instantiated otherwise, it is garbage-collected like 
all other classes. Otherwise, someone could store a refcounted 
exception into a global object reference. Then the program would 
have to check for reference count every time when adding or 
deleting an object reference, slowing down the whole program.

In catch blocks, where the caught exception may or may not be 
refcounted, they are marked scope so there won't be refcounted 
classes running wild, only at the catch scope.


More information about the Digitalmars-d mailing list