confusion around CustomException example in 'Python in a Nutshell'

wittempj@hotmail.com martin.witte at gmail.com
Fri Mar 11 18:54:33 EST 2005


I don't know the mentioned book, but if you rewrite like:
>>> import sys
>>> class LinuxDriverError(Exception):
...     def __init__(self, *args):
...         Exception.__init__(self, *args)
...         self.message = args[0]
...
...     def __str__(self):
...         return str(sys.exc_info())
...
>>> def test():
...     raise LinuxDriverError, "raising Cain!"
...
>>> try:
...     test()
... except LinuxDriverError, error:
...     print error
...
(<class __main__.LinuxDriverError at 0x401e305c>,
<__main__.LinuxDriverError instance at 0x401deb6c>, <traceback object
at 0x401df20c>)
>>>     # just checking
...     print "sys.exc_info(): ", sys.exc_info()

This gets what you probably expect, the way you do it there is no
traceback object when you print it




More information about the Python-list mailing list