Try block problem
Greg Krohn
volucris at hotmail.com
Tue Nov 20 00:37:32 EST 2001
"Jeff Davis" <jdavis at empires.org> wrote in message
news:9tcnls$42k$1 at news1.ucsd.edu...
> It seems like the following makes sense to me:
>
> try:
> ...
> except:
> ...
> finally:
> ...
except and finally can't be used together.
>>> def spam(x):
... try:
... print 10 / x
... finally:
... print 'Cleanup before exception is raised'
...
>>> def eggs(x):
... try:
... print 10 / x
... except:
... print 'Bad x! Bad, bad x!'
...
>>> spam(1)
10
Cleanup before exception is raised
>>> spam(0)
Cleanup before exception is raised
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "<interactive input>", line 3, in spam
ZeroDivisionError: integer division or modulo by zero
>>> eggs(1)
10
>>> eggs(0)
Bad x! Bad, bad x!
More info: http://www.python.org/doc/current/ref/try.html
greg
More information about the Python-list
mailing list