anuraguni...@yahoo.com wrote:
import sys
try:
    raise "xxx"
except str,e:
    print "1",e # is not caught here
except:# is caught here
    print "2",sys.exc_type,sys.exc_value

In the above code a string exception is raised which though deprecated
but still a 3rd party library I use uses it. So how can I catch such
exception without relying on catch all, which could be bad.

system: Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) [GCC 4.2.3
(Ubuntu 4.2.3-2ubuntu7)] on linux2

Just fix the except type to be the exception caused by the illegal "raise"

except TypeError,e:
   print "1",e # is caught here


1 exceptions must be classes or instances, not str

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to