[Python-Dev] PEP 310 and exceptions
bh at intevation.de
Sat Apr 23 19:59:29 CEST 2005
Nick Coghlan <ncoghlan at gmail.com> writes:
> holger krekel wrote:
>> Moreover, i think that there are more than the "transactional"
>> use cases mentioned in the PEP. For example, a handler may want to
>> log exceptions to some tracing utility or it may want to swallow
>> certain exceptions when
>> its block does IO operations that are ok to fail.
> With the current PEP 310 definition, these can be manually handled using
> sys.exc_info() in the __exit__ method.
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.
if hasattr(var, "__enter__"):
An empty except: suite suffices. In C that's equivalent to a call to
Intevation GmbH http://intevation.de/
More information about the Python-Dev