Peter Scott wrote:
>
> Tony Olekshy wrote:
> >
> >         try     { TryToFoo; }
> >         catch   { TryToHandleFailure; }
> >         finally { TryToCleanUp; }
> >         catch   { throw "Can't cleanly Foo."; };
> >
> >In our production code we often add such blocks to major API entry
> >points; that is how we get unwind stack tracebacks like the one
> >shown in RFC 88:
>
> Um, I still don't geddit.  Why don't you put that last throw in the
> finally block?  That's where I would have expected to find it.

Like this?
              try     { TryToFoo; }
              catch   { TryToHandleFailure; }
              finally { TryToCleanUp;
                        throw "Can't cleanly Foo.";
                        };

Since finally is invoked every time, if I put the throw in there
then it will throw even if TryToFoo didn't throw and TryToCleanUp
didn't throw, that is, even if I was able to cleanly Foo (in which
case I certainly don't want a "Can't cleanly Foo" exception).

In addition, the throw won't be invoked if TryToCleanUp throws, in
which case I won't get the extra "Can't cleanly Foo" exception on the
unwind stack, which was the whole point of the exercise.

Like this?
              try     { TryToFoo; }
              catch   { TryToHandleFailure; }
              finally { throw "Can't cleanly Foo.";
                        TryToCleanUp;
                        };

Um, TryToCleanUp will never be called.

Yours, &c, Tony Olekshy

Reply via email to