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 忽略 异常