exceptions with spaces don't work??
Paul Probert
pprobert at facstaff.wisc.edu
Mon Apr 7 20:14:13 EDT 2003
As a python newbie, I came across a problem:
If I raise an exception with a string, as in:
raise 'somestring'
then my statement
except 'somestring':
will catch it unless there are spaces. For instance
suppose I have a file ext.py:
def re():
raise 'x y'
return 3
try:
print 'calling re'
x=re()
except 'x y':
print 'got it'
now execute it:
>>> execfile('ext.py')
calling re
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "ext.py", line 7, in ?
x=re()
File "ext.py", line 2, in re
raise 'x y'
x y
now replace the spaces with _:
def re():
raise 'x_y'
return 3
try:
print 'calling re'
x=re()
except 'x_y':
print 'got it'
>>> execfile('ext.py')
calling re
got it
Is this a bug??
--
Paul Probert
The University of Wisconsin-Madison
More information about the Python-list
mailing list