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

Gonçalo Rodrigues op73418 at mail.telepac.pt
Fri Jan 31 01:10:16 CET 2003

On Thu, 30 Jan 2003 22:43:15 -0000, claird at lairds.com (Cameron Laird)


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

Does this solve your problem?

>>> try:
... 	raise TypeError("This is a whacky example!")
... except Exception, e:
... 	print e
This is a whacky example!

Inheritance-works-with-exceptions-ly yours,
G. Rodrigues

More information about the Python-list mailing list