
Paul Prescod wrote:
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.
I wouldn't say that: exceptions can have error handlers, callbacks, inherited attributes, etc. etc. and you can put these to good use in your application.
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.
I don't know what should be "unpythonic" about having a single root for exceptions. Would someone care to explain ? To me ... try: ... except Exception, errobj: # catches all exceptions pass ... is the most natural way of using that single root (and it already works great today).
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).
-- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Aug 05 2004)
Python/Zope Consulting and Support ... http://www.egenix.com/ mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::