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

Michael Hudson mwh at python.net
Fri Jan 31 16:32:39 CET 2003


claird at lairds.com (Cameron Laird) writes:

> 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'.
>       cope(e)
> Yes, I can write
>   ....
>   except:
>       cope()
> but then I've lost the information I want in 'e'.

>>> class C:
...  pass
... 
>>> raise C
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: exceptions must derive from Exception

Nah, I made that up.  I do wonder if it should be enforced, though.

I would say that if the library you're using raises exceptions that
aren't derived from Exception the proper solution involves physical
discomfort for the author of the library.

Cheers,
M.

-- 
  : Giant screaming pieces of excrement, they are.
  I have a feeling that some of the people in here have a 
  MUCH more exciting time relieving themselves than I do.
                                       -- Mike Sphar & Dave Brown, asr




More information about the Python-list mailing list