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 块,程序将崩溃并引发错误