Defining a new exception with multiple args

Daniel Klein danielk at aracnet.com
Thu Jan 11 10:14:25 EST 2001


Using the Beazley book as a guide, I have defined a new exception as:

class RecordNotFoundException(Exception):
    def __init__(self, filename, recordid):
        self.filename = filename
        self.recordid = recordid

However, this is what happens when I raise this exception:

>>> raise RecordNotFoundException("myfile", "myid")
Traceback (innermost last):
  File "<pyshell#40>", line 1, in ?
    raise RecordNotFoundException("myfile", "myid")
RecordNotFoundException: <unprintable instance object>

>>> raise RecordNotFoundException, ("myfile", "myid")

produces the same result.

I also tried defining the exception with

import exception
class RecordNotFoundException(exception.Exception):

Why is it showing '<unprintable instance object>' instead of the arguments I
passed?

Thanks for any assistence,
Daniel Klein



More information about the Python-list mailing list