[Tutor] exception question

Gonçalo Rodrigues op73418 at mail.telepac.pt
Wed Apr 28 09:23:42 EDT 2004


Em Wed, 28 Apr 2004 12:59:46 +0100, Dave S <pythontut at pusspaws.net>
atirou este peixe aos pinguins:

Forwarding to the list, since by mistake sent it only to Dave.

[text snipped]

>My problem is I do not know what the exception error will be.
>I have a script that will run 247, If an error occurs I want it to 
>e-mail me with the exception
>error that caused the crash.
>
>Is this possible ?

Does the following help?

>>> try:
... 	raise TypeError
... except Exception, e:
... 	print repr(e)
... 
<exceptions.TypeError instance at 0x01108B20>


The Exception (old-style) class is the mother of all exception
classes, so the above will catch *every* error. This is usually bad
policy because it can mask error that you may want to propagate. By
your description, this  is not a problem. Still if you want to filter
out some "errors" like KeyboardInterrupt for example do the following:

>>> try:
... 	raise TypeError
... except KeyboardInterrupt:
... 	raise
... except Exception, e:
... 	print repr(e)
... 
<exceptions.TypeError instance at 0x0110EAA8>


Hope it helps, with my best regards,
G. Rodrigues



More information about the Tutor mailing list