Traceback objects in python

1.6k views Asked by At

I was debugging my python script and came across traceback object, which is present at 2nd index in result, returned by sys.exc_info() function. However, I tried to google out information related to traceback object, but everywhere i got link to traceback module in standard python lib. Then, I tried doing dir() on traceback object, which gives me a list of attributes. In that list, following attributes looks interesting :-

 1. tb_frame,
 2. tb_lasti,
 3. tb_lineno,
 4. tb_next

I know about tb_frame and tb_lineno, but what rest of other attributes indicates ?

Apologizing for bad English. Thanks in advance.

1

There are 1 answers

0
Mangu Singh Rajpurohit On

As specified by in docpage specified by @vaultah,

These all are special read-only attributes.

  1. 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;
  2. tb_frame points to the execution frame of the current level;
  3. tb_lineno gives the line number where the exception occurred;
  4. tb_lasti indicates the precise instruction.

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.