欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > python >内容正文

python

python 忽略 异常_如何忽略Python中的异常?

发布时间:2023/12/1 python 40 豆豆
生活随笔 收集整理的这篇文章主要介绍了 python 忽略 异常_如何忽略Python中的异常? 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

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

总结

以上是生活随笔为你收集整理的python 忽略 异常_如何忽略Python中的异常?的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。