User-defined Exceptions: is self.args OK?

Petr Jakeš petr.jakes at tpc.cz
Thu Apr 17 18:11:36 EDT 2008


Hi,
I have posted this via google.groups, but I have discovered many of you are
filtering such a postings.

So this is my second try from the mail client.

I am trying to dig through User-defined Exceptions.  chapter 8.5 in
http://docs.python.org/tut/node10.html


I would like to know, if is it OK to add following line to the __init__
method of the TransitionError class?

self.args = (self.previous, self.next, self.message)


If I do not add this argument to the class, object created by exception does
not include values from self.previous, self.next, self.message attributes in
the

print traceback.format_exc()

for example:

===== 8< snipp 8< ========

class TransitionError(Error):

def __init__(self, previous, next, message):
    self.previous = previous
    self.next = next
    self.message = message


try:
    raise  TransitionError('previous error %s' % 'fooo', 'nextBar', 'this is
foo bar message')
except TransitionError,  err:
    print err
    print err.args
    import traceback, sys
    print sys.exc_info()
    traceback.print_exc()

===== 8< snipp 8< ========

Thanks for your replies.

Petr Jakes
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080418/82c3ab49/attachment.html>


More information about the Python-list mailing list