我有一个错误raise eb : list index out of range
。在
我不明白为什么我在另一家公司加薪try - catch
我在一个try - catch
中执行try - catch
,这两个操作都会引发错误。在
这是我的代码,错误行位于raise eb
:
try:
print("debut edit")
print(p)
modif_box = get_modif_box_profile(p)
post_box = get_Post_Box(p)
print("modi_box")
print(modif_box)
print("mbu id")
print(modif_box.id)
diff = {}
posts = {}
new_post = []
diff["posts"] = posts
posts["modified_post"] = new_post
for post in modif_box.edit_post_user.all():
# print(post.id_mod)
try:
messagenew = post_box.post.all().filter(id=post.id_mod)[0]
# print(post_new)
print("posts")
print(post)
# todo a factoriser
if messagenew.id > int(last_id) and messagenew.sender.id != p.id:
name = get_name_contact(p, messagenew)
return_post = {}
return_post["uid"] = messagenew.sender.id
return_post["pid"] = messagenew.id
return_post["author"] = name
return_post["title"] = messagenew.title
return_post["date"] = unix_time_millis(messagenew.date)
return_post["smile"] = count_smile(messagenew)
return_post["comment"] = count_comment(messagenew)
return_post["data"] = messagenew.data
return_post["type"] = messagenew.type_post.type_name
new_post.append(return_post)
else:
print("depop edit")
modif_box.edit_post_user.remove(post)
modif_box.save()
except Exception as eb:
PrintException()
# raise eb (if i decomment here i have an error in my program)
print(diff)
return diff
except Exception as e:
PrintException()
raise e
致以问候和感谢
如果您对}。在
raise
语句进行注释,并不意味着您不存在错误;它只是意味着您处理了Exception
,在您的例子中,我可以用except Exception
捕捉它,然后调用PrintException()
来告诉{当您^{} 出现异常时,您实际要做的是:
因此,通过取消注释,您可以允许名为
eb
的IndexError
在内部try-except
块中捕获后重新出现,并被外部的try - except
子句捕获,在该子句中再次引发它。在一般来说,您不希望以这种通用的方式捕捉异常,因为它可能会隐藏一些您希望了解的程序的不可预测行为。在
限制在except子句中捕获的异常,方法是在您的示例中,指定一个except子句,格式如下:
可能就够了。在
相关问题 更多 >
编程相关推荐