Python's Exception, and Capitalization
wittempj@hotmail.com
martin.witte at gmail.com
Fri Aug 12 11:05:11 EDT 2005
For youtr try, except, finally:
you can construct something like this:
try:
try:
print 'egg' + 1
except ValueError, e:
print e
finally:
print 'spam'
It results in:
py>
spam
Traceback (most recent call last):
File "C:/Martin/test.py", line 3, in -toplevel-
print 'egg' + 1
TypeError: cannot concatenate 'str' and 'int' objects
py>
If you catch the TypeError you get:
try:
try:
print 'egg' + 1
except TypeError, e:
print e
finally:
print 'spam'
py>
cannot concatenate 'str' and 'int' objects
spam
py>
More information about the Python-list
mailing list