title: How to get the name of an exception that was caught in Python?
body: <p>How can I get the name of an exception that was raised in Python?</p>
  
  <p>e.g.,</p>
  
  <pre><code>try:
      foo = bar
  except Exception as exception:
      name_of_exception = ???
      assert name_of_exception == 'NameError'
      print "Failed with exception [%s]" % name_of_exception
  </code></pre>
  
  <p>For example, I am catching multiple (or all) exceptions, and want to print the name of the exception in an error message.</p>