[Python-Dev] PEP 310 and exceptions

Nick Coghlan ncoghlan at gmail.com
Sun Apr 24 03:22:17 CEST 2005


Bernhard Herzog wrote:
> With the proposed implementation of PEP 310 rev. 1.5 it wouldn't work.
> sys.exc_info returns a tuple of Nones unless an except: clause has been
> entered.  Either sys.exc_info() would have to be changed to always
> return exception information after an exception has been raised or the
> implementation would have to be changed to do the equivalent of e.g.

Interesting. Although the 'null' except block should probably be a bare 'raise', 
rather than a 'pass':

Py> try:
...   try:
...     raise TypeError("I'm an error!")
...   except:
...     raise
... finally:
...   print sys.exc_info()
...
(<class exceptions.TypeError at 0x009745A0>, <exceptions.TypeError instance at 0
x009E7238>, <traceback object at 0x009E72B0>)
Traceback (most recent call last):
   File "<stdin>", line 3, in ?
TypeError: I'm an error!

All the more reason to consider switching to a nested try/finally + 
try/except/else definition for 'with' blocks, I guess.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://boredomandlaziness.skystorm.net


More information about the Python-Dev mailing list