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

Nick Coghlan ncoghlan at gmail.com
Fri Mar 27 13:41:15 CET 2009

Hrvoje Niksic wrote:
> How about:
> try:
>     ... code that can raise Thing or another exception ...
> except Exception, e:
>     if isinstance(e, Thing):
>         # handle thing
>     # generic exception handling

That is indeed the idiomatic way of handling the original poster's use
case without nesting a second try block.

Any proposals for new dedicated syntax should probably go to
python-ideas rather than here though. (It's a rare enough use case that
I don't like the original poster's chances of getting much support for
changes though)


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

More information about the Python-Dev mailing list