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

Hrvoje Niksic hrvoje.niksic at avl.com
Fri Mar 27 13:31:41 CET 2009


Mark Donald wrote:
> I frequently have this situation:
> 
> try:
>     try:
>         raise Thing
>     except Thing, e:
>         # handle Thing exceptions
>         raise
> except:
>     # handle all exceptions, including Thing

How about:

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


More information about the Python-Dev mailing list