At 09:13 PM 8/16/00 -0600, Tony Olekshy wrote:
>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.
Okay, I see. Unfortunately, this violates the no-daisychaining rule and is
IMHO hard to understand at first.
I see why you want it, though. That does look nice like that. Without it
you need to:
try {
try { TryToFoo; }
catch { TryToHandleFailure; }
finally { TryToCleanUp; }
}
catch { throw "Can't cleanly Foo." }
There may be other issues here though. I'm not an expert on program flow
design, so this may be wrong, but it seems to me that there ought to be a
distinction between some of the cases you're collapsing above:
1. TryToFoo succeeds, TryToCleanUp succeeds
- Post-finally throw: no
2. TryToFoo succeeds, TryToCleanUp fails
- Post-finally throw: yes
3. TryToFoo fails, TryToHandleFailure succeeds, TryToCleanUp succeeds
- Post-finally throw: no
4. TryToFoo fails, TryToHandleFailure succeeds, TryToCleanUp fails
- Post-finally throw: yes
5. TryToFoo fails, TryToHandleFailure fails, TryToCleanUp succeeds
- Post-finally throw: yes
6. TryToFoo fails, TryToHandleFailure fails, TryToCleanUp fails
- Post-finally throw: yes
Do I have that list right? Especially #3?
Rats. It just doesn't look right the way you have it. There shouldn't be
anything after a 'finally' block.
--
Peter Scott
Pacific Systems Design Technologies