How to catch str exception?
MRAB
google at mrabarnett.plus.com
Fri May 15 10:17:15 EDT 2009
anuraguniyal at yahoo.com wrote:
> but the whole point of catching such exception is that i can print its
> value
> there are many such exceptions and hence it is not feasible to catch
> them all or know them all unless i go thru src code.
>
If string exceptions are so difficult to use, don't use them! :-)
It would be better to write your own exception class:
class MyException(Exception):
pass
try:
raise MyException("Something bad happened!")
except MyException, e:
print "ERROR: %s" % e
More information about the Python-list
mailing list