如果没有抛出异常,我想执行一些代码。
目前我正在这样做:
try:
return type, self.message_handlers[type](self, length - 1)
finally:
if not any(self.exc_info()):
self.last_recv_time = time.time()
这可以改进吗?这是最好的方法吗?
更新0
The optional else clause is executed if and when control flows off the end of the try clause.
Currently, control “flows off the end” except in the case of an exception or the execution of a return, continue, or break statement.
最佳答案
try:
tmp = type, self.message_handlers[type](self, length - 1)
except Exception:
pass #or handle error, or just "raise" to re-raise
else:
self.last_recv_time = time.time()
return tmp
关于python - 如果没有抛出异常则执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6911999/