When is bare except: justified?

Peter Hansen peter at engcorp.com
Fri Dec 5 14:05:03 EST 2003


Dave Brueck wrote:
> 
> > When *is* it justified to use except:, then?

> The rule of thumb I use is that a bare except is bad if it hides the fact that
> an exception occurred. So, for example, using a bare except in code like this
> is okay:
> 
> for worker in workers:
>   try:
>     worker.process()
>   except:
>     LogException()

Ah, the sheer elegant beauty of that viewpoint.  Thanks, Dave!  It clearly
covers all the use cases we have, with a much, much smaller rationalization
than I've tried to use.

-Peter




More information about the Python-list mailing list