title: Monkey Patching Exception class and other builtin classes
body: <p>Regardless of the Excpetion type, I would like to print a message whenever an exception occurs.</p>
  
  <p>I tried the following:</p>
  
  <pre><code>class MyException(BaseException):
    def __init__(self, msg):
      super(BaseException, self).__init__(msg)
      print "Howdy", msg
  
  __builtins__.Exception = MyException
  
  try:
    raise IOError("world")
  except Exception as e:
    pass
  </code></pre>
  
  <p>I expected "Howdy world" to be printed but instead I get nothing.</p>
  
  <p>EDIT:</p>
  
  <p>@helmut suggested using sys.settrace, the following code works as expected.</p>
  
  <pre><code>import sys
  
  def trace(frame, event, arg):
      print event
      return trace
  
  sys.settrace(trace)
  
  def foo():
      raise Exception()
  
  def bar():
      foo()
  
  def baz():
      try:
          bar()
      except:
          pass
  
  baz()
  
  exit()
  </code></pre>
  
  <p>Too bad this is too slow for my use case.</p>