DMD 0.148 - scope guard

Regan Heath regan at netwin.co.nz
Sun Feb 26 13:17:04 PST 2006


On Sun, 26 Feb 2006 12:20:58 -0800, Kyle Furlong <kylefurlong at gmail.com>  
wrote:
> What I understand from your proposal: (how it should have been)
> void LongFunction()
> failure
> {
> 	clean_what_foo1_did();
> 	clean_what_foo2_did();
> 	clean_what_foo3_did();
> 	clean_what_foo4_did();
> }
> body
> {
> 	foo1();
> 	foo2();
> 	foo3();
> 	foo4();
> }

In the above:
  - is clean_what_foo1_did only called if foo1() has returned successfully  
and foo2,foo3,or foo4 failed?
  - is clean_what_foo2_did only called if foo2() has returned successfully  
and foo3,or foo4 failed?
  - is clean_what_foo3_did only called if foo3() has returned successfully  
and foo4 failed?

(there is actually no point to clean_what_foo4_did)

Because, this is an important part of the scope guard feature, each  
on_scope_failure statement registers something which is then called on  
failure of the scope in which it is registered. The order in which they  
are registered WRT the other code is important.

Regan



More information about the Digitalmars-d mailing list