title: How to save traceback / sys.exc_info() values in a variable?
body: <p>I want to save the name of the error and the traceback details into a variable.  Here's is my attempt.</p>
  
  <pre><code>import sys
  try:
      try:
          print x
      except Exception, ex:
          raise NameError
  except Exception, er:
      print "0", sys.exc_info()[0]
      print "1", sys.exc_info()[1]
      print "2", sys.exc_info()[2]
  </code></pre>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>0 &lt;type 'exceptions.NameError'&gt;
  1 
  2 &lt;traceback object at 0xbd5fc8&gt;
  </code></pre>
  
  <p><strong>Desired Output:</strong></p>
  
  <pre><code>0 NameError
  1
  2 Traceback (most recent call last):
    File "exception.py", line 6, in &lt;module&gt;
      raise NameError
  </code></pre>
  
  <p>P.S. I know this can be done easily using the traceback module, but I want to know usage of sys.exc_info()[2] object here.</p>