Plan for Exceptions and @nogc?

Jonathan Marler via Digitalmars-d digitalmars-d at puremagic.com
Tue Feb 17 10:30:23 PST 2015


On Tuesday, 17 February 2015 at 18:04:53 UTC, Matthias Bentrup 
wrote:
> If the unwinding is done after the exception handler is left, 
> the thrower can safely reference the data directly on the stack 
> and the catcher can ignore any data it doesn't need. (It may 
> copy the data to safety if it is needed later, but the catcher 
> knows what it needs, whereas the thrower has to always assume 
> the worst case.)

That is a good idea, unfortunately this is impossible since the 
catch block needs to execute code. But this is a good thought 
process.  I thought of the same thing but then realized that it 
would be impossible to ensure that the catch block wouldn't stomp 
on that memory.  This leads to having a second stack...however, 
we already have a solution...it's called the heap :)  By the time 
you're done trying to resolve this issue you will have just 
redesigned the heap.

IMO, Allocating the exception on the non-gc heap and making the 
catch block responsible for freeing the memory is a pretty good 
solution.


More information about the Digitalmars-d mailing list