In fortran, I use goto for rollbacks, and I usually start 999 back (in fortran, goto labels are only numeric)
call foo(err) if (err /= 0) goto 999 call bar(err) if (err /= 0) goto 998 call baz(err) if (err /= 0) goto 997 ! everything fine error = 0 return 997 call undo_bar() 998 call undo_foo() 999 error = 1 return
I also use tags greater than 1000 if for some reason I want to skip part of the rollback.
In C and other languages, I would use rollbacknumber (e.g. rollback1, rollback2), so it will clear the label you are about to roll back. This is essentially the only good reason to use goto.
source share