python - Why exc_traceback returns None -


sys.exc_info() returns tuple (type , value, traceback).
sys.exc_info()[2] our traceback object.

why not catch exceptions traceback code:

import sys  try:     1/0 except zerodivisionerror:     print sys.exc_info()[2].tb_frame.f_back 

tb_frame , f_back usage has been explained here: frame objects

you see none because there no outer frame. you're executing directly, current frame last frame. demonstrate this, created demo.py:

import sys  try:     1/0 except zerodivisionerror:     print sys.exc_info()[2].tb_frame.f_back 

which should familiar, , trivial caller.py:

import demo 

now see difference:

$ python demo.py none  $ python caller.py <frame object @ 0x10bc34c20> 

in second case, there outer frame (i.e. caller.py), don't see none.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -