[Tutor] exception question

Dave S pythontut at pusspaws.net
Wed Apr 28 07:59:46 EDT 2004


Gonc,alo Rodrigues wrote:

>Em Wed, 28 Apr 2004 09:48:59 +0100, Dave S <pythontut at pusspaws.net>
>atirou este peixe aos pinguins:
>
>  
>
>>Is it possible, for the code after except to know the exception type. I 
>>know I can do multiple "except"s for each condition but this is not 
>>realy what I want.
>>
>>try:
>>   ....
>>   ...code...
>>   ....
>>except:
>>   ...code ....
>>
>>    
>>
>
>Sure. The following is, I believe, self-explanatory:
>
>  
>
>>>>try:
>>>>        
>>>>
>... 	raise TypeError
>... except ValueError:
>... 	print "Got a ValueError"
>... except TypeError:
>... 	print "Got a TypeError"
>... 	
>Got a TypeError
>
>You can also "catch" the exception object itself:
>
>  
>
>>>>try:
>>>>        
>>>>
>... 	raise TypeError("This is a type error")
>... except TypeError, e:
>... 	print "TypeError found!"
>... 	print "Error: %r." % e
>... 	print "Arguments of exception object: %r." % e.args
>... 	
>TypeError found!
>Error: <exceptions.TypeError instance at 0x010DD530>.
>Arguments of exception object: 'This is a type error'.
>  
>
>
>Hope it helps, with my best regards,
>G. Rodrigues
>
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>
>  
>
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 ?

Dave



More information about the Tutor mailing list