How to catch str exception?

Dave Angel davea at ieee.org
Fri May 15 11:48:02 EDT 2009



anuraguniyal at yahoo.com wrote:
>> except TypeError,e:
>>     print "1",e # is caught here
>>
>> 1 exceptions must be classes or instances, not str
>>     
>
> doesn't happen so in 2.5.2
>
>   
I tested it in 2.6.2

Perhaps you could try something like:

try:
    raise "xxx"
except Exception, e:
    print "1",e # is caught here
    ...and then test e.message and reraise if necessary





More information about the Python-list mailing list