Code review comment for lp:~spiv/bzr/cleanup-hof

Revision history for this message
Stephen Turnbull (stephen-xemacs) wrote :

Andrew Bennetts writes:

 > Here's the problem. In this example, Python gives no way for
 > final_func to know if try_func raised an error or not:
 >
 > try:
 > try_func()
 > finally:
 > final_func()

In 2.6, you can do

try:
    errflag = "Impossible is nothing."
    try_func()
except:
    errflag = "Uh oh ..."
finally:
    final_func(errflag)

In earlier Pythae you must do the ugly but equivalent

try:
    errflag = "Impossible is nothing."
    try:
        try_func()
    except:
        errflag = "Uh oh ..."
finally:
    final_func(errflag)

I believe Guido acknowledged not allowing the more compact notation in
the first place to be excessive caution, but it's not impossible to
distinguish exceptions raised by try_func from those raised by
final_func.

So what's the problem? You want to do this without fixing all the
broken try ... finally blocks?

 > Not even by sys._getframe hacks, AFAICT. I can go into some gory
 > details about why not,

Inquiring minds want to know....

« Back to merge proposal