Bug or feature? std.c.stdlib.exit() breaks RAII

Stewart Gordon smjg_1998 at yahoo.com
Fri Jan 6 04:06:36 PST 2012


On 29/12/2011 19:09, Jacob Carlborg wrote:
<snip excessive quote>
> Could druntime hook up on the atexit function to run destructors and similar when the
> program exits?

I'm not sure.  Maybe it could be called upon to run static destructors and destruct 
heap-allocated objects.  But in order to call scope guards and RAII, it would need to 
unwind the call stack, which could get complicated if you're trying to do it from within a 
function.

It's much simpler not to use exit() and throw a custom exception instead.

Stewart.


More information about the Digitalmars-d-learn mailing list