星期日, 十月 08, 2006

python: Exceptions try/except/finally syntax?

注意:没有 try/except/finally 语法
>>> try:
... raise "trying"
... except "trying":
... print "catch it"
... finally:
File "", line 5
finally:
^
SyntaxError: invalid syntax
只能如下:
>>> try:
... try:
... raise "trying"
... finally:
... print "finally"
... except "trying":
... print "catch it"
...
finally
catch it

1 条评论:

Roc Zhou 说...

从 Python 2.5 开始支持 try/except/finally 语法!