[Python-3000] self-contained exceptions

Phillip J. Eby pje at telecommunity.com
Fri Jan 5 02:56:57 CET 2007


At 12:18 AM 1/5/2007 +0100, Malte Helmert wrote:
>Phillip J. Eby wrote:
> > Heck, you could even say the translation is:
> >
> >       except ExcType:
> >           e = sys.exception  # or whatever it's called in 3K
> >           try:
> >               # body
> >           finally:
> >               e = None
> >               del e
> >
> > Although I suppose you can't actually implement it that way.  :)
>
>What should happen in the last line here?
>
>def f():
>     e = "spam"
>     try:
>         1 / 0
>     except Exception, e:
>         print e
>     print e

It should fail with an UnboundLocalError; anything else (IMO) would 
encourage "overly clever" code that's hard for a reader to decipher.



More information about the Python-3000 mailing list