why scope(success)?

Sean Kelly sean at f4.ca
Sat May 13 12:25:25 PDT 2006


Mike Capp wrote:
> In article <e42jr6$2u07$1 at digitaldaemon.com>, Walter Bright says...
>> For example, if I have operations A(), B(), and C(), and A.rollback(), 
>> B.rollback() and C.rollback:
>>
>> 	A();
>> 	scope(failure) A.rollback();
>> 	B();
>> 	scope(failure) B.rollback();
>> 	C();
>> 	scope(failure) C.rollback();
>>
>> Just for fun, try to do that with either C++ exceptions or Java try-finally.
> 
> Off the top of my head...
> 
> struct A // ditto for B and C
> {
> A() { doA(); }
> ~A() { if (std::uncaught_exception()) { rollbackA(); } }
> };

It's probably a matter of implementation, but std::uncaught_exception 
isn't terribly useful in C++.  The most obvious reason being that it 
acts globally rather than specific to the calling thread.  I'm also not 
sure I like that the dtor would change behavior based on whether an 
exception is in flight.  This results in unexpected behavior, which is 
never a good thing.


Sean



More information about the Digitalmars-d mailing list