[New-bugs-announce] [issue8082] Misleading exception when raising an object

Daniel Eloff report at bugs.python.org
Sun Mar 7 00:31:36 CET 2010


New submission from Daniel Eloff <dan.eloff at gmail.com>:

>>> 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.

----------
messages: 100551
nosy: Daniel.Eloff
severity: normal
status: open
title: Misleading exception when raising an object
type: behavior
versions: Python 2.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8082>
_______________________________________


More information about the New-bugs-announce mailing list