Raising objects

Jan Olderdissen jolderdissen at ixiacom.com
Tue Apr 29 15:55:03 EDT 2003


Carlos,

since object is a type object
(http://www.python.org/doc/current/lib/bltin-type-objects.html) and
not a string, class or instance of a class you can't raise it or
classes derived from it.

That said, I question the point of deriving from object as classes
(and in fact all objects as far as I can tell) are derived from object
as it is. Since object isn't a class, deriving from it probably is
bogus to begin with. What exactly are you trying to do?

Jan

On 29 Apr 2003 08:50:42 -0700, cpitaar at yahoo.com.ar (Carlos P.) wrote:

>Hi all,
>
>I have this short question: can the operator 'raise' raise exceptions
>which are instances of object? I'm getting the following behaviour
>from python 2.2.2:
>
>>>> class F: pass
>
>>>> raise F()
>Traceback (most recent call last):
>  File "<stdin>", line 1, in ?
>__main__.F: <__main__.F instance at 0x8136bf4>
>
>>>> class E(object): pass
>
>>>> raise E()
>Traceback (most recent call last):
>  File "<stdin>", line 1, in ?
>TypeError: exceptions must be strings, classes, or instances, not E
>
>Thank you,
>Carlos





More information about the Python-list mailing list