title: How can you programmatically inspect the stack trace of an exception in Python?
body: <p>When an exception occurs in Python, can you inspect the stack?  Can you determine its depth?  I've looked at the <a href="http://docs.python.org/library/traceback.html" rel="noreferrer">traceback</a> module, but I can't figure out how to use it.</p>
  
  <p>My goal is to catch any exceptions that occur during the parsing of an eval expression, without catching exceptions thrown by any functions it may have called.  Don't berate me for using eval.  It wasn't my decision.</p>
  
  <p>NOTE: I want to do this programmatically, not interactively.</p>