建議更好的處理 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