[Python-Dev] Python in Unicode context

Paul Prescod paul at prescod.net
Thu Aug 5 04:32:30 CEST 2004


Greg Ewing wrote:

>...
>>I don't really think that "raise 42"
>>ought to be acceptable, but I don't know how to prevent it
> 
> 
> Maybe we need to think more deeply about *why* it shouldn't be
> acceptable. If we can figure out exactly what the criterion should be,
> maybe we can think of a reasonable way of testing for it.

Exceptions naturally form a hierarchy. At the same time, inheritance of 
behaviour among exceptions is seldom necessary. Therefore, exceptions 
inherit from each other in order to build a classification system, not 
to share code. This is the opposite of the traditional reasons for 
classes inheriting from other classes in Python. This is why it seems 
"unpythonic" to require exceptions to be single-rooted.

But having a proper classification system is exactly what is required to 
allow robust, modular code that catches the right exceptions under the 
right circumstances and responds in the right way. So it is pythonic 
after all.

In a few senses the _current model_ is unpythonic. There is no catch-all 
root so you have to use a "bare" except to catch every exception type. 
This makes it hard to introspect on the caught object. But 
introspection is the MOST IMPORTANT THING when you are catching all 
exceptions (because you should be logging the exception or something).

  Paul Prescod



More information about the Python-Dev mailing list