[Python-Dev] Exception hierarchy [was Re: Another test_compiler mystery] (original) (raw)

Aahz aahz at pythoncraft.com
Tue Aug 17 03:01:56 CEST 2004


On Mon, Aug 16, 2004, James Y Knight wrote:

The criteria for whether a given exception should go under "Exception" or "FatalError" is whether users' code should generally catch the exception. Thus, at least "SystemExit", "KeyboardInterrupt", and "MemoryError" should go under "FatalError". Catching those is nearly never what you wanted to do when you write "except Exception:". There's likely more -- I have not gone through all the exceptions in Python to classify them. One issue is that creating a new category of Exceptions doesn't help people who do "except:" instead of "except Exception:". It is unlikely that person meant to catch things like MemoryError, rather, they were just being lazy. I suppose that syntax could be deprecated, at least in example code and documentation, in favor of "except Exception" for the usual case, and "except Raisable" for the cases where you do actually want to catch everything*.

We've already got StandardError; I think it makes more sense to rearrange the exception hierarchy a bit to support your suggestion rather than creating a whole new base class.

Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/

"To me vi is Zen. To use vi is to practice zen. Every command is a koan. Profound to the user, unintelligible to the uninitiated. You discover truth everytime you use it." --reddy at lion.austin.ibm.com



More information about the Python-Dev mailing list