【发布时间】:2016-02-12 07:48:22
【问题描述】:
我有这样的代码:
try:
return make_success_result()
except FirstException:
handle_first_exception()
return make_error_result()
except SecondException:
handle_second_exception()
return make_error_result()
我想知道有什么办法可以做到这一点:
try:
# do something
except Error1:
# do Error1 specific handling
except Error2:
# do Error2 specific handling
else:
# do this if there was no exception
????:
# ALSO do this if there was ANY of the listed exceptions (e.g. some common error handling)
所以代码按以下顺序之一执行:
try > else > finally
try > except > ???? > finally
编辑:我的意思是
????块应该在任何except块之后立即执行,这意味着它是对错误处理的补充,而不是替代。
【问题讨论】:
标签: python exception exception-handling try-except