- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在 Python 2.6 上有一个包含与此类似的部分的脚本:
import sys
list_id='cow'
prev=[0,'cow']
try:
if list_id==prev[1]:
print '{0} is the same as {1}'.format(list_id,prev[1])
sys.exit(0)
except:
print 'exception occurred, exiting with error'
sys.exit(1)
我注意到虽然它打印了“是相同的”行,但它也记录了异常!
如果删除 try/except block ,解释器不会显示错误。如果您捕获到特定错误,如 ValueError,则不会执行 except block 。
import sys
list_id='cow'
prev=[0,'cow']
try:
if list_id==prev[1]:
print '{0} is the same as {1}'.format(list_id,prev[1])
sys.exit(0)
except Exception as k:
print 'exception occurred, exiting with error. Exception is:'
print k.args
sys.exit(1)
except block 未执行,进程结束并返回代码 0。那么,异常在层次结构中位于 Exception 之上?
import sys
list_id='cow'
prev=[0,'cow']
try:
if list_id==prev[1]:
print '{0} is the same as {1}'.format(list_id,prev[1])
sys.exit(0)
except BaseException as k:
print 'exception occurred, exiting with error. Exception is:'
print k.args
sys.exit(1)
产生
cow is the same as cow exception occurred, exiting with error.
Exception is: (0,)
进程以退出代码 1 结束。
为什么要执行这个 Except block ?
最佳答案
sys.exit()
提高 SystemExit
,这就是您所看到的。
关于为什么不继承Exception
:
The exception inherits from
BaseException
instead ofStandardError
orException
so that it is not accidentally caught by code that catchesException
. This allows the exception to properly propagate up and cause the interpreter to exit.
关于python - 这个没有特色的 Python 异常是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7477533/
嗯,我的问题是,我想存储某种产品在他们自己的表中,并且从这些产品中我想选择一些到特色/强调产品表,它将存储每个表中所选行的 ID,以在网站的主页上显示这些特色产品。 从表中选择特色产品后,我想自己制定
您好,我正在与 bigcommerce 合作,我希望在每个类别页面上获得以下风格的分割 本质上是制作类别版本; %%Panel.HomeFeaturedProducts%% %%Panel.SideT
在这个网站上http://rwl.rwlwater.com/我有一个小问题...我添加了 overflow: hidden 到特色 slider div,如果启用了 javascript 或用户的互联
我用VB.NET和MySQL作为数据库创建了一个咖啡销售系统。 在该系统中,用户可以更新自己的信息,例如名字、姓氏、BOD 等。 但是,多个用户当前可能会同时编辑同一数据集,这是我需要防止的。 示例:
在这里http://jsfiddle.net/comparebest/yBcKk/6/我有一个 jQuery slider 和两个 Div - DIV ONE 和 DIV TWO。 有没有办法让我自动
我是一名优秀的程序员,十分优秀!