> 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()
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,
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: func(errflag)
errflag = "Impossible is nothing."
try_func()
except:
errflag = "Uh oh ..."
finally:
final_
In earlier Pythae you must do the ugly but equivalent
try: func(errflag)
errflag = "Impossible is nothing."
try:
try_func()
except:
errflag = "Uh oh ..."
finally:
final_
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....