From: "Fred L. Drake, Jr." email@example.com
Guido van Rossum writes:
I wish I had done it right from the start -- then exceptions would have been classes from the start and would have required inheritance from the Exception base class. Like in Java. (And in C++?)
I've seen this said or hinted at in a couple of places (the specific requirement that exception derive from Exception), but I've seen nothing that indicates any reason or derived value for this. Could someone please clarify?
It's simply an extra bit of checking that your program is reasonable -- if you accidentally raise a non-exception class, there's probably something wrong with your program, and it gives the reader a hint about the intended use of the class.
Other languages (e.g. Modula-3) have a specific exception type that can be used only for that one purpose. However it's useful to allow methods an subclassing of exceptions, so they might as well be classes. So, all exceptions are classes. But not all classes are exceptions.
--Guido van Rossum (home page: http://www.python.org/%7Eguido/)