title: Is it possible to catch multiple types of exceptions and then print the exact type that occurred?
body: <p>This is the <a href="https://stackoverflow.com/questions/6470428/catch-multiple-exceptions-in-one-line-except-block">closest answer</a> I could find on catching multiple exceptions (the correct way), when after a miracle of acquiescence the interpreter allowed the following snippet:</p>
  
  <pre><code>try:
      x = "5" + 3
  except NameError and TypeError as e:
      print e
  </code></pre>
  
  <p>The <a href="http://docs.python.org/2/tutorial/errors.html" rel="nofollow noreferrer">docs</a> would provide this snippet as well, but nothing like the former:</p>
  
  <pre><code>... except (RuntimeError, TypeError, NameError):
  ...     pass
  </code></pre>
  
  <p>So it would be nice to have a second opinion, but my question really comes down to this:</p>
  
  <ul>
  <li>How can I not only print the message, but insert at the beginning of the print statement the exact type of error raised. For example I would prefer the first snippet to respond by printing this instead: <code>TypeError: cannot concatenate 'str' and 'int' objects</code></li>
  </ul>
  
  <p>I feel like it probably is not possible, or easy, given that the interpreter lists only <code>args</code> and <code>message</code> as members of <code>NameError</code> but perhaps that is simply incomplete.</p>
  
  <p>I have tried this myself, but it no longer excepts the errors (I might be misunderstanding isinstance):</p>
  
  <pre><code>try:
      x = "5" + 3
  except (NameError, TypeError) as e:
      if isinstance(e, NameError):
          print "NameError: " + e
      elif isinstance(e, TypeError):
          print "TypeError: " + e
      else:
          print e
  </code></pre>