[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-dev
Subject:    Re: [Python-Dev] PEP 310 and exceptions
From:       Bernhard Herzog <bh () intevation ! de>
Date:       2005-04-23 17:59:29
Message-ID: s9z64yde5mm.fsf () thetis ! intevation ! de
[Download RAW message or body]

Nick Coghlan <ncoghlan@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__"):
	var.__enter__()

    try:
        try:
            suite
        except:
            pass
    finally:
        var.__exit__()


An empty except: suite suffices.  In C that's equivalent to a call to
PyErr_NormalizeException AFAICT.



   Bernhard

-- 
Intevation GmbH                                 http://intevation.de/
Skencil                                           http://skencil.org/
Thuban                                  http://thuban.intevation.org/
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/python-dev%40progressive-comp.com
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic