title: Formatting exceptions as Python does
body: <p>If I raise an Exception in Python, here's what I get:</p>
  
  <pre><code>raise Exception("Hello world")
  Traceback (most recent call last):
  
    File "&lt;ipython-input-24-dd3f3f45afbe&gt;", line 1, in &lt;module&gt;
      raise Exception("Hello world")
  
  Exception: Hello world
  </code></pre>
  
  <p>Note the last line that says <code>Exception: Hello world</code>. Given an Exception (<code>foo = Exception("Hello world")</code>), how can I produce text like this? None of the following work:</p>
  
  <pre><code>str(foo)
  Out[27]: 'Hello world'
  
  repr(foo)
  Out[28]: "Exception('Hello world',)"
  
  "{}".format(foo)
  Out[29]: 'Hello world'
  
  "{}: {}".format(type(foo), foo)
  Out[30]: "&lt;type 'exceptions.Exception'&gt;: Hello world"
  </code></pre>