'This function is called if an exception occurs,
but only if we are to stop at or just below this level.'

def user_exception(self, frame, exc_info):

    if self._wait_for_mainpyfile:
        return
    (exc_type, exc_value, exc_traceback) = exc_info
    frame.f_locals['__exception__'] = (exc_type, exc_value)
    if (type(exc_type) == type('')):
        exc_type_name = exc_type
    else:
        exc_type_name = exc_type.__name__
    print >>self.stdout, (exc_type_name + ':'), _saferepr(exc_value)
    self.interaction(frame, exc_traceback)
