[Python-ideas] suggestion for try/except program flow

Nick Coghlan ncoghlan at gmail.com
Sun Mar 29 08:33:31 CEST 2009

Mark Donald wrote:
>> Guido already said this, but yes, something did change in 3.0: unlike
>> the 2.x series, the raise statement in 3.x only accepts instances of
>> BaseException, so having both an "except BaseException:" clause and a
>> bare "except:" clause becomes redundant.
> Ah, apologies... I need to update myself.
> 'uncatch' to subsequently execute the else clause is still going to be
> impossible, but I don't have a real-world need for that as yet.

If you really find yourself doing this kind of exception interrogation a
lot, you may find it easier to do it in the __exit__ method of a context
manager. Those are *always* invoked regardless of how the with statement
ends and you can then do whatever flow control you like based on the
type of the first argument (and whether or not it is None).


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-ideas mailing list