Python 錯誤處理
The try
block lets you test a block of code for errors.
The except
block lets you handle the error.
The finally
block lets you execute code, regardless of the result of the try- and except blocks.
異常處理
當發生錯誤時,或者我們稱之為異常時,Python 通常會停止並生成錯誤訊息。
這些異常可以使用 try
語句進行處理
由於 try 塊引發了錯誤,將執行 except 塊。
沒有 try 塊,程式將崩潰並引發錯誤