Which exception has been used? (was: Which exception to use?)

Cameron Laird claird at lairds.com
Thu Jan 30 23:43:15 CET 2003

In article <7h3y954ywdw.fsf at pc150.maths.bris.ac.uk>,
Michael Hudson  <mwh at python.net> wrote:
>Chad Netzer <cnetzer at mail.arc.nasa.gov> writes:
>> I do things like this for some library functions that I create (I 
>> welcome discussion about whether it is a good approach)
>> class ArgumentError( Exception ):
>>     pass
>This *is* a good approach (IMHO), but you should consider deriving
>your exceptions from StandardError instead (I rarely remember to do
>this, either).
And what about people who don't?

I've liked this thread for its serious presentations
of the results of deep experience.  I still suspect
I'm at least two big insights from comfort with ex-
ceptions, though.

One of my problems is that I don't know how to write
"the default case".  When we see the above, I assume
we all have in mind client code that looks like
 except SpecializedError, e:
 except StandardError, e:

Suppose, as is always true, though, that I'm dealing
with modules not under my control.  How do I catch
"other"?  There must be something I'm missing about
the new type and exception systems, 'cause I don't 
see a Pythonic way to write
  except OTHER, e:
      # The foreign code threw an exception of
      #    a type I don't recognize, but I need
      #    to process/log/... 'e'.
Yes, I can write
but then I've lost the information I want in 'e'.

Cameron Laird <Cameron at Lairds.com>
Business:  http://www.Phaseit.net
Personal:  http://phaseit.net/claird/home.html

More information about the Python-list mailing list