else: w/o except: - why not?

Michael Chermside mcherm at mcherm.com
Thu Apr 3 12:18:46 EST 2003


Michael Chermside wrote:
> I think that a "bare except" is useful in only two ways. The first
> is like a "finally" clause that's skipped if everything works.
[...snip...]
> The other situation is running "untrusted plug-in" code of some 
> sort.

David Eppstein replies:
> I have a bare except wrapped around the main event loop of some python 
> gui code.  It provides an opportunity to log the problem and give the 
> user a chance to clean up instead of just immediately crashing.
> Doesn't seem to fit into either of your two uses, but I think it's a 
> legit use.

David Bolen replies:
> In our case [...], a large amount of our Python code
> deals with distributed systems management and communications, and
> there are quite a few cases where we have bare excepts in order to
> catch any exceptions to be packaged and either reported (as part of a
> plugin or dynamic module system as you show above), propagated to some
> client, or just logged and execution resumed.

Good point guys. I think I should add a third senario... that of 
capturing exceptions for logging or changing how they're reported
to the user.

-- Michael Chermside






More information about the Python-list mailing list