This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Misleading exception when raising an object
Type: behavior Stage:
Components: Versions: Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Daniel.Eloff, barry, benjamin.peterson
Priority: normal Keywords:

Created on 2010-03-06 23:31 by Daniel.Eloff, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg100551 - (view) Author: Daniel Eloff (Daniel.Eloff) Date: 2010-03-06 23:31
>>> class Foo(object):
...     pass
...     
>>> raise Foo()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
TypeError: exceptions must be classes or instances, not Foo
>>> class Foo(Exception):
...     pass
...     
>>> raise Foo()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
Foo
>>> class Foo(BaseException):
...     pass
...     
>>> raise Foo()
Traceback (most recent call last):
  File "<input>", line 1, in <module>
Foo

It seems exceptions can only be subclasses of BaseException, the error message is confusing and false.
msg100554 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2010-03-07 00:01
Done in r78746.
msg100607 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2010-03-07 20:48
Minor nit: it's questionable whether this should have gone in between 2.6.5 rc1 and rc2.  It doesn't seem like a critical fix.  OTOH, it also seems harmless enough so I'm gonna let it slide.
msg100615 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2010-03-07 22:46
2010/3/7 Barry A. Warsaw <report@bugs.python.org>:
>
> Barry A. Warsaw <barry@python.org> added the comment:
>
> Minor nit: it's questionable whether this should have gone in between 2.6.5 rc1 and rc2.  It doesn't seem like a critical fix.  OTOH, it also seems harmless enough so I'm gonna let it slide.

Thank you. My apologies for forgetting the state of that tree.
History
Date User Action Args
2022-04-11 14:56:58adminsetgithub: 52329
2010-03-07 22:46:13benjamin.petersonsetmessages: + msg100615
2010-03-07 20:48:43barrysetnosy: + barry
messages: + msg100607
2010-03-07 00:01:01benjamin.petersonsetstatus: open -> closed

nosy: + benjamin.peterson
messages: + msg100554

resolution: fixed
2010-03-06 23:31:35Daniel.Eloffcreate