Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 上升中上升错误_Python_Python 3.x_Raise - Fatal编程技术网

Python 上升中上升错误

Python 上升中上升错误,python,python-3.x,raise,Python,Python 3.x,Raise,我有一个错误将eb:list索引提高到超出范围 我不明白为什么我在另一家公司加薪 我正在一个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(mod

我有一个错误
将eb:list索引提高到超出范围

我不明白为什么我在另一家公司加薪 我正在一个
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语句允许程序员强制发生指定的异常

因此,通过取消注释,您允许名为
eb
索引器在内部
try-except
块中捕获后重新出现,并被外部
try-except
子句捕获,在该子句中您再次重新引发它


通常,您不希望以这种通用的方式捕获异常,因为它可能会隐藏一些您希望了解的程序的不可预测的行为

在您的情况下,只需指定以下形式的except子句,即可限制在except子句中捕获的异常:

except IndexError as eb:
    PrintException() 

可能就足够了

请包括您的跟踪