scope + destructor with Exception parameter for RAII

Leandro Lucarella llucarella at integratech.com.ar
Thu Nov 30 09:58:12 PST 2006


Sean Kelly escribió:
>> I don't see why writing correct code is that complicated. And how do 
>> you address the problem of repeating error handling code and the lack 
>> of encapsulation of scope(success/failure)?
> 
> The lack of encapsulation doesn't bother me much, though now I see what 
> you're getting at.  I do think that having:
> 
>     auto scope t = new Transaction();
>     scope(failure) t.rollback();
>     // commits if not rolled back on scope exit, alternately use
>     scope(success) t.commit();
> 
> actually aids readability a bit, at the expense of some extra code.

So you are against all RAII done in the C++ way, I guess...

> That said, I have considered adding a routine that the user can call to 
> determine whether an exception is in flight.  Similar to the one in C++, 
> but without all the annoying shortcomings.  It would mean setting a 
> thread-local flag or pointer in the internal exception handling code, 
> etc.  I think this is a better approach than altering dtor syntax for 
> the same purpose, as it avoids language changes and doesn't lose any 
> usefulness in the process.

I see this more as a hack than a clean solution (I don't say the dtor 
Exception parameter is heaven but I see it a little more cleaner =), but 
its fair enough.

I didn't know C++ had a way to determine an exception is in flight...

>> Any other thoughts on this (the thread diverged a little from the 
>> original topic ;)?
> 
> See above :-)

Thanks, really =)

-- 
Leandro Lucarella
Integratech S.A.
4571-5252



More information about the Digitalmars-d mailing list