Proposal 2: Exceptions and @nogc
Andrew Godfrey via Digitalmars-d
digitalmars-d at puremagic.com
Mon Apr 10 06:41:55 PDT 2017
On Monday, 10 April 2017 at 06:17:43 UTC, Dukc wrote:
> 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.
Thanks for explaining!
Now I get it.
I'm just curious: The proposal doesn't mention interop with C++
exception handlers. I don't know the status of that so I'll just
ask: Can C++ code catch D exceptions?
More information about the Digitalmars-d
mailing list