New style classes as exceptions (Was: exception handing)
Denis S. Otkidach
ods at fep.ru
Mon Jul 1 09:52:07 EDT 2002
On 29 Jun 2002, Chris Liechti wrote:
CL> Rhymes <rhymes at myself.com> wrote in
CL> news:pan.2002.06.29.17.41.28.926443.440 at myself.com:
CL> ...
CL> >>>> ex1 = "spam"
CL> >>>> try:
CL> > ... raise ex1
CL> > ... except ex1:
CL> > ... print 'got it'
CL> > ...
CL> > got it
CL> ...
CL>
CL> exceptions are instances of classes nowdays... don't use
CL> strings. and avoid
CL> troubles...
New style classes don't work when used as exceptions. I guess it
should be considered as a bug.
>>> class o(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