try except bug
ÀÌ°¼º
gslee at pymail.net
Thu Jan 9 23:31:01 EST 2003
I think there is a bug in try-except clause.
If you use 'raise' with a string type exception and class instance, that's
OK. But, when you 'raise' with a class type exception and class instance, it
works in a strange way. Look at the following code.
class MessageClass:
def __init__(self):
self.message = 'message'
self.duration = 10
def f():
raise Exception, MessageClass()
def g():
raise 'Exception', MessageClass()
try:
g()
except 'Exception', a:
print a, type(a)
print a.duration # This one works fine
try:
f()
except Exception, a:
print a, type(a)
print a.duration # This one doesn't work.
The result is ------------
<__main__.MessageClass instance at 0x007E9870> <type 'instance'>
10
<__main__.MessageClass instance at 0x007E8E10> <type 'instance'>
Traceback (innermost last)
File "Untitled", line 22, in ?
print a.duration
AttributeError: Exception instance has no attribute 'duration'
I'm using Python 2.2.2
Do you have any idea about this?
Gang Seong
More information about the Python-list
mailing list