#Python異常處理
try: #捕獲異常
pass
except: #所有處理異常
print("當try執行過程中發生異常,執行except進行處理,不會暫停程序,反之except不會執行")
#多層異常處理
try: #捕獲異常
pass
except ValueError: #處理異常
print("當try執行過程中發生異常,執行except進行處理,不會暫停程序,反之except不會執行")
except ZeroDivisionError: #處理異常
print("當try執行過程中發生異常,執行except進行處理,不會暫停程序,反之except不會執行")
except: #其他錯誤處理
print("當try執行過程中發生異常,執行except進行處理,不會暫停程序,反之except不會執行")
#多層異常處理
try: #捕獲異常
pass
except (ZeroDivisionError,ValueError) as info: #多異常處理
print("錯誤原因",info)
raise #錯誤處理不了 再次拋出異常
except: #其他錯誤處理
print("當try執行過程中發生異常,執行except進行處理,不會暫停程序,反之except不會執行")
#人爲拋出異常指定錯誤
raise ValueError("錯誤原因")