[英]Traceback objects in python
I was debugging my python script and came across traceback<\/code> object, which is present at 2nd index in result, returned by
sys.exc_info()<\/code> function.
我正在调试我的 python 脚本并遇到了
traceback<\/code>对象,该对象存在于结果中的第二个索引处,由
sys.exc_info()<\/code>函数返回。
However, I tried to google out information related to
traceback<\/code> object, but everywhere i got link to
traceback module<\/code> in standard python lib.
但是,我试图用谷歌搜索出与
traceback<\/code>对象相关的信息,但是在任何地方我都得到了标准 python 库中
traceback module<\/code>的链接。
Then, I tried doing
dir()<\/code> on traceback object, which gives me a list of attributes.
然后,我尝试在回溯对象上执行
dir()<\/code> ,它给了我一个属性列表。
In that list, following attributes looks interesting :-
在该列表中,以下属性看起来很有趣:-
1. tb_frame,
2. tb_lasti,
3. tb_lineno,
4. tb_next
As specified by in docpage specified by @vaultah,正如@vaultah 指定的文档页中所指定的那样,
These all are special read-only attributes.这些都是特殊的只读属性。
tb_next
is the next level in the stack trace (towards the frame where the exception occurred), or None if there is no next level; tb_next
是堆栈跟踪中的下一个级别(朝向发生异常的帧),如果没有下一个级别,则为 None;tb_frame
points to the execution frame of the current level; tb_frame
指向当前关卡的执行帧;tb_lineno
gives the line number where the exception occurred; tb_lineno
给出发生异常的行号;tb_lasti
indicates the precise instruction. tb_lasti
表示精确指令。 Note :- The line number and last instruction in the traceback may differ from the line number of its frame object if the exception occurred in a try statement with no matching except clause or with a finally clause.注意:-如果异常发生在没有匹配 except 子句或 finally 子句的 try 语句中,则回溯中的行号和最后一条指令可能与其框架对象的行号不同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.