title: Exception in Python Exception Class's __str__ Missed
body: <p>Does anybody know how to catch exceptions in python Exception's derived classes's <code>__str__</code> function? And how to debug that <code>__str__</code> using pdb since I find it doesn't work when invoke <code>pdb.set_trace()</code> or setting breakpoint in pdb in function <code>__str__</code>.</p>
  
  <p>Example code:</p>
  
  <pre><code>class Ex(Exception):
      def __str__(self):
          raise KeyError('1')
  
  raise Ex()
  </code></pre>
  
  <p>The output is</p>
  
  <pre><code>Traceback (most recent call last):
    File "./exex.py", line 10, in &lt;module&gt;
      raise Ex()
  __main__.Ex
  </code></pre>
  
  <p>While I think the output should be something like </p>
  
  <pre><code>KeyError: '1'
  </code></pre>
  
  <p>And if I add <code>pdb.set_trace()</code> before <code>raise KeyError('1')</code>, python runtime does not interrupt at <code>pdb.set_trace()</code>. So does anyone know how to debug <code>Exception.__str__</code> when it is a little complex?</p>
  
  <hr>
  
  <p>Sorry for the <code>pdb.set_trace()</code> case. It works. However, if you forget to put <code>import pdb</code>, then python slightly ignore the exception which looks like <code>pdb.set_trace()</code> is ignored. </p>
  
  <p>While setting breakpoint in pdb still does not work.</p>