[Python-3000] self-contained exceptions

Phillip J. Eby pje at telecommunity.com
Thu Jan 4 16:00:10 CET 2007


At 01:41 AM 1/4/2007 -0600, Ka-Ping Yee wrote:
>How about this?
>
>      except ExcType, e:
>          try:
>              # body
>          finally:
>              e = None

It's a little bit more difficult to explain in the reference manual.  I was 
figuring we'd say that the exception variable is bound only in the body of 
the except clause; saying it becomes None when you exit sounds weirder to 
me.  How about:

      except ExcType, e:
          try:
              # body
          finally:
              e = None
              del e

Then we get the best of all three worlds: a clean explanation, a clean 
implementation, and a pure source-to-source transformation.

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.  :)



More information about the Python-3000 mailing list