Since traceback objects can not be pickled, this function manipulates
    exception info tuples before they are passed accross process
    boundaries.
488784
def serializeable_exc_info(thetype, ex, tb):
    
    return thetype, ex, ''.join(traceback.format_exception(thetype, ex, tb))
619768
def ExceptionHook(exctype, value, tb):
    '''
    

    '''

    for line in traceback.format_exception_only(exctype, value):
        log.error(line.replace('\n', ''))
    for line in traceback.format_tb(tb):
        log.error(line.replace('\n', ''))
    sys.__excepthook__(exctype, value, tb)
268795
def handleError(exception, debugFlag=False, abortFlag=True):
    """"""
    if isinstance(exception, CmdError) or not debugFlag:
        error(str(exception))
    else:
        import traceback
        traceback.print_exc()
        error(str(exception))   # or log complete traceback as well?
    if abortFlag:
        sys.exit(1)
395108
def excepthook(exc_type, exc_value, tracebackobj):
    
    separator = "-" * 80
    notice = "The following error was triggered:"

    now = datetime.now().strftime("%Y-%m-%d, %H:%M:%S")

    info = StringIO()
    traceback.print_tb(tracebackobj, None, info)
    info.seek(0)
    info = info.read()

    errmsg = f"{exc_type}\t \n{exc_value}"
    sections = [now, separator, errmsg, separator, info]
    msg = "\n".join(sections)

    print(''.join(traceback.format_tb(tracebackobj)))
    print('{0}: {1}'.format(exc_type, exc_value))

    QtWidgets.QMessageBox.warning(None, notice, traceback.format_exc())
776660
def set_exception_info(self, exception, traceback):
        
        with self._condition:
            self._exception = exception
            self._traceback = traceback
            self._state = FINISHED
            for waiter in self._waiters:
                waiter.add_exception(self)
            self._condition.notify_all()
        self._invoke_callbacks()
179070
def _install_exception_handler(self):
        
        def handler(t, value, traceback):
            if self.args.verbose:
                sys.__excepthook__(t, value, traceback)
            else:
                sys.stderr.write('%s\n' % unicode(value).encode('utf-8'))

        sys.excepthook = handler
663157
def _exception_raise(self):
        
        exc = self.exc_info()[:]
        try:
            exc_type, exc_value, exc_traceback = exc
        except ValueError:
            exc_type, exc_value = exc
            exc_traceback = None

        # raise exc_type(exc_value).with_traceback(exc_traceback)
        if sys.version_info[0] == 2:
            exec("raise exc_type, exc_value, exc_traceback")
        else: #  sys.version_info[0] == 3:
            if isinstance(exc_value, Exception): #hasattr(exc_value, 'with_traceback'):
                # If exc_value is an exception, then just reraise
                exec("raise exc_value.with_traceback(exc_traceback)")
            else:
                # else we'll create an exception using the value and raise that
                exec("raise exc_type(exc_value).with_traceback(exc_traceback)")
209346
def showtraceback(self, *args, **kwargs):
        """"""
        # Override for avoid using sys.excepthook PY-12600
        try:
            type, value, tb = sys.exc_info()
            sys.last_type = type
            sys.last_value = value
            sys.last_traceback = tb
            tblist = traceback.extract_tb(tb)
            del tblist[:1]
            lines = traceback.format_list(tblist)
            if lines:
                lines.insert(0, "Traceback (most recent call last):\n")
            lines.extend(traceback.format_exception_only(type, value))
        finally:
            tblist = tb = None
        sys.stderr.write(''.join(lines))
370264
def _error(self, exc_info):
        
        if self._exc_info:
            if self._traceback:
                return exc_info
            return exc_info[:2]
        return exc_info[1]
1307637
def _error(self, exc_info):
        
        if self.exc_info:
            if self.traceback:
                return exc_info
            return exc_info[:2]
        return exc_info[1]
658626
def catches(exc, handler=re_raise):
    '''
    
    '''
    if not __CHECKING__:
        return lambda f: f

    def wrap(f):
        def call(*args, **kwd):
            try:
                ID = exc_checker.set_attention(exc)
                res = f(*args, **kwd)
                exc_checker.remove_attention(exc, ID)
                return res
            # handle checked exception
            except exc, e:
                exc_checker.remove_attention(exc, ID)
                traceback = sys.exc_info()[2]
                return handler(exc, str(e), traceback.tb_next.tb_next)
            # re-raise unchecked exception but remove checked exeption info first
            except Exception, e:
                exc_checker.remove_attention(exc, ID)
                traceback = sys.exc_info()[2]
                raise e.__class__, e.args, traceback.tb_next.tb_next
        call.__name__ = f.__name__
        return call
    return wrap
1022313
def process_exception(self, request, exception):
        
        if hasattr(threadlocal, 'auditlog'):
            pre_save.disconnect(sender=LogEntry, dispatch_uid=threadlocal.auditlog['signal_duid'])

        return None
908180
def exception_catcher(fn):
    
    exceptions = Queue.Queue()

    @wraps(fn)
    def wrapped(*args, **kwargs):
        try:
            ret = fn(*args, **kwargs)
        except Exception:
            exceptions.put(sys.exc_info())
            raise
        return ret

    def check():
        try:
            item = exceptions.get(block=False)
            klass, value, tb = item
            raise klass, value, tb
        except Queue.Empty:
            pass

    setattr(wrapped, 'check', check)
    return wrapped
215572
def handle_exception(self, frame, exc_info):
        """"""
        type_, value, tb = exc_info
        # Python 3 is broken see http://bugs.python.org/issue17413
        _value = value
        if not isinstance(_value, BaseException):
            _value = type_(value)
        fake_exc_info = type_, _value, tb
        log.error('Exception during trace', exc_info=fake_exc_info)
        self.obj_cache[id(exc_info)] = exc_info
        self.extra_vars['__exception__'] = exc_info
        exception = type_.__name__
        exception_description = str(value)
        init = 'Echo|%s' % dump({
            'for': '__exception__',
            'val': escape('%s: %s') % (exception, exception_description)
        })
        # User exception is 4 frames away from exception
        frame = frame or sys._getframe().f_back.f_back.f_back.f_back
        self.interaction(
            frame, tb, exception, exception_description, init=init
        )
973879
def format_exc(limit=None):
    """"""
    try:
        etype, value, tb = sys.exc_info()
        return ''.join(traceback.format_exception(etype, value, tb, limit))
    finally:
        etype = value = tb = None
1261430
def make_traceback(exc_info, source_hint=None):
    """"""
    exc_type, exc_value, tb = exc_info
    if isinstance(exc_value, TemplateSyntaxError):
        exc_info = translate_syntax_error(exc_value, source_hint)
        initial_skip = 0
    else:
        initial_skip = 1
    return translate_exception(exc_info, initial_skip)
862365
def no_exception(on_exception, logger=None):
    

    def decorator(function):
        def wrapper(*args, **kwargs):
            try:
                result = function(*args, **kwargs)
            except Exception, e:
                if hasattr(logger, 'exception'):
                    logger.exception(e)
                else:
                    print traceback.format_exc()
                result = on_exception
            return result

        return wrapper

    return decorator