How to catch str exception?

MRAB google at
Fri May 15 16:17:15 CEST 2009

anuraguniyal at 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):

     raise MyException("Something bad happened!")
except MyException, e:
     print "ERROR: %s" % e

More information about the Python-list mailing list