python异常:如何打印嵌套try的所有调试信息?

2024-05-14 19:52:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我有代码:

try:
    print test.qwerq]
    try:
        print test.sdqwe]
    except:
        pass
except:
   pass

如何打印嵌套try中所有错误的调试信息?在


Tags: 代码test错误passprinttryexcept调试信息
1条回答
网友
1楼 · 发布于 2024-05-14 19:52:55

重新引发异常。在

try:
    print test[qwerq]
    try:
        print test[qwe]
    except:
        # Do something with the exception.
        raise
except:
   # Do something here too, just for fun.
   raise

需要注意的是,一般情况下你不想这样做。如果你不打算做任何事情的话,最好不要捕捉到异常。在

如果只想打印调用堆栈而不崩溃,请查看traceback模块。在

相关问题 更多 >

    热门问题