Exception Safe Programming

renoX renosky at free.fr
Sun Feb 25 03:31:33 PST 2007


Saaa a écrit :
> On the website there is the following example:
> 
> Transaction abc()
> {
>     Foo f;
>     Bar b;
> 
>     f = dofoo();
>     try
>     {
>     	b = dobar();
>     	return Transaction(f, b);
>     }
>     catch (Object o)
>     {
>     	dofoo_undo(f);
>     	throw o;
>     }
> }
> 
> When f=dofoo() is run and doesn't succeed I suspect that f hasn't changed 
> and dofoo has thrown an exception.
> Because of the exception the try part isn't run, but the catch part is.
> Did I understand this correctly?
> The explanation of the try statement on the website is not the most 
> comprehensible one (^.^)

That's probably because this is a counter-example, not an example 
really: more a (convincing) way to show that scope() is much better than 
try/catch for exception safe programming..

renoX


More information about the Digitalmars-d-learn mailing list