如何在没有异常的情况下使用“except 子句”用 Python?


如果我们定义了没有异常的 except 子句,它可以处置所有类型的异常。但这不是一个良好的编码实践,也不推荐使用。

try:
print 'foo'+'qux'+ 7
except:
print' There is error'

输出

你可以获得输出

There is error

这种类型的 Python try-except 块可以处置所有类型的异常,但不能帮助程序员发现发生了哪种类型的异常。

更新于:12-2月-2020

2 千 + 浏览

助力您的 事业

完成课程认证

开始
广告
© . All rights reserved.