New style classes as exceptions (Was: exception handing)

Denis S. Otkidach ods at fep.ru
Mon Jul 1 11:49:38 EDT 2002


On Mon, 1 Jul 2002, Mark McEahern wrote:

MM> > New style classes don't work when used as exceptions.  I
MM> guess it
MM> > should be considered as a bug.
MM>
MM> Just out of curiousity:  How come you aren't subclassing
MM> from Exception?

This doesn't matter:

>>> class o(Exception, object): pass
...
>>> try:
...     raise o('spam')
... except o:
...     print 'OK'
...
Traceback (most recent call last):
  File "<stdin>", line 2, in ?
TypeError: exceptions must be strings, classes, or instances, not o






More information about the Python-list mailing list