scope + destructor with Exception parameter for RAII
BCS
BCS at pathilink.com
Tue Nov 28 13:30:50 PST 2006
Sean Kelly wrote:
> Leandro Lucarella wrote:
>> What do you think of adding an optional parameter (exception) to the
>> destructor, defaulting to null, to indicate the destructor was called
>> then unwinding because an exception was thrown? Then you can almost
>> forget about scope(exit/success/failure) and you have a RAII as
>> complete as Python's 'with' statement.
>
> I don't like it, personally. It doesn't seem a good idea for a dtor to
> alter its behavior based on whether an exception is in flight, and
> exceptions should never be thrown from dtors anyway. Doing so makes
> writing correct code far too complicated.
>
> One thing I have done for Ares, however, is to terminate the program if
> one exception is thrown while another is in flight. I think DMD/Phobos
> does not do this currently, and instead either ignores the new
> exception, or substitutes it for the in-flight exception (I can't
> remember which).
>
>
> Sean
I think this works under DMD
try
{
throw new Error("some stuff");
}
catch(Error e)
{
throw new Error("more stuff\n"~e.toString);
}
It could be vary handy to have this ability to swap out one exception
for another.
More information about the Digitalmars-d
mailing list