python 忽略 異常
什么是例外? (What is an Exception?)
An exception is an event, which occurs during the execution of a program that interrupts the normal execution of the application. Generally, any application when encountered with a situation that it can not handle (or such implementation is not implemented), the application throws ( or raises in Python) an exception.
異常是事件,該事件在程序執行期間發生,中斷了應用程序的正常執行。 通常,任何應用程序遇到無法處理的情況(或此類實現未實現)時,該應用程序都會引發(或在Python中引發)異常。
The exception that is a runtime, blows the application. However, it is a good practice to always handle the exception immediately than let the application propagate which might terminate the application with a bulk error message.
運行時的異常會炸毀應用程序。 但是,最好始終立即處理異常,而不是讓應用程序傳播,這可能會以大量錯誤消息終止應用程序。
在Python中處理異常 (Handling Exception in Python)
The try-except syntax is as follows:
try-except語法如下:
try:
statements
except Exception1:
<handle exception 1>
except Exception2:
<handle exception2>
else:
print("Nothing went wrong")
finally:
print("will'be executed regardless if the try block raises an error or not")
忽略異常 (Ignoring the exceptions)
When you want to ignore an exception, use the key word "pass". Below are few examples,
當您想忽略異常時,請使用關鍵字“通過”。 以下是一些示例,
try:
<do something>
except:
pass
try:
<do something>
except Exception:
pass
翻譯自: https://www.includehelp.com/python/how-to-ignore-exceptions.aspx
python 忽略 異常