【发布时间】:2009-08-22 13:41:42
【问题描述】:
当我用 Python 编写带有异常处理的代码时,我可以编写如下代码:
try:
some_code_that_can_cause_an_exception()
except:
some_code_to_handle_exceptions()
else:
code_that_needs_to_run_when_there_are_no_exceptions()
这与以下有何不同:
try:
some_code_that_can_cause_an_exception()
except:
some_code_to_handle_exceptions()
code_that_needs_to_run_when_there_are_no_exceptions()
在这两种情况下,code_that_needs_to_run_when_there_are_no_exceptions() 都会在没有异常时执行。有什么区别?
【问题讨论】: