建议更好的处理 Python 异常的方法
我们可以使用 finally 子句来清理是否抛出异常
try: #some code here except: handle_exception() finally: do_cleanup()
如果在异常事件中进行清理,我们可以按如下方式编码
should_cleanup = True try: #some code here should_cleanup = False except: handle_exception() finally: if should_cleanup(): do_cleanup()
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编码
C++
C#
MongoDB
MySQL
Javascript
PHP