Take an exception object and return a generator with vtml formatted
    exception traceback lines.
558900
def format_exception(exc, indent=0, pad='  '):
    
    from_msg = None
    if exc.__cause__ is not None:
        indent += yield from format_exception(exc.__cause__, indent)
        from_msg = traceback._cause_message.strip()
    elif exc.__context__ is not None and not exc.__suppress_context__:
        indent += yield from format_exception(exc.__context__, indent)
        from_msg = traceback._context_message.strip()
    padding = pad * indent
    if from_msg:
        yield '\n%s%s\n' % (padding, from_msg)
    yield '%s<b><u>Traceback (most recent call last)</u></b>' % padding
    tblist = traceback.extract_tb(exc.__traceback__)
    tbdepth = len(tblist)
    for x in tblist:
        depth = '%d.' % tbdepth
        yield '%s<dim>%-3s</dim> <cyan>File</cyan> "<blue>%s</blue>", ' \
            'line <u>%d</u>, in <b>%s</b>' % (padding, depth, x.filename,
                                              x.lineno, x.name)
        yield '%s      %s' % (padding, x.line)
        tbdepth -= 1
    yield '%s<b><red>%s</red>: %s</b>' % (padding, type(exc).__name__, exc)
    return indent + 1
387607
def exception_format():
    
    return "".join(traceback.format_exception(
        sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2]
    ))
792350
def _from_exception(cls, pe):
        
        return cls(pe.pstr, pe.loc, pe.msg, pe.parserElement)
875822
def trace_generator(trace, start=0, stop=None, step=1):
    
    i = start
    stop = stop or np.inf
    size = min(trace.length(), stop)
    while i < size:
        index = slice(i, i + 1)
        yield trace.gettrace(slicing=index)[0]
        i += step
545291
def replace_exceptions(
    old_to_new_exceptions: Dict[Type[BaseException], Type[BaseException]]
) -> Callable[..., Any]:
    
    old_exceptions = tuple(old_to_new_exceptions.keys())

    def decorator(to_wrap: Callable[..., Any]) -> Callable[..., Any]:
        @functools.wraps(to_wrap)
        # String type b/c pypy3 throws SegmentationFault with Iterable as arg on nested fn
        # Ignore so we don't have to import `Iterable`
        def wrapper(
            *args: Iterable[Any], **kwargs: Dict[str, Any]
        ) -> Callable[..., Any]:
            try:
                return to_wrap(*args, **kwargs)
            except old_exceptions as err:
                try:
                    raise old_to_new_exceptions[type(err)] from err
                except KeyError:
                    raise TypeError(
                        "could not look up new exception to use for %r" % err
                    ) from err

        return wrapper

    return decorator
239958
def withTracebackPrint(ErrorType, thrownError, _traceback):
    ''''''
    file = StringIO.StringIO()
    traceback.print_exception(ErrorType, thrownError, _traceback, file = file)
    return _loadError(ErrorType, thrownError, file.getvalue())
1277688
def exception_handler(exceptionObj):
    """"""
    try:
        if isinstance(exceptionObj, Exception) and hasattr(exceptionObj, 'args'):
            if not (hasattr(exceptionObj, 'message' or hasattr(exceptionObj, 'msg'))):
                if len(exceptionObj.args) >= 1:
                    if type(exceptionObj.args[0]) == type(b''):
                        ob = json.loads(exceptionObj.args[0].decode('utf-8'))
                        if type(ob) == type({}) and ob['message']:
                            return ob['message']
                    else:

                        try:
                            if type(exceptionObj.args[0]) == type('') and exceptionObj.args[0][0] == 'b':
                                ob = json.loads(exceptionObj.args[0][2:-1])
                            else:
                                ob = json.loads(exceptionObj.args[0])
                            if type(ob) == type({}) and ob['message']:
                                try:
                                    return exception_handler(ob['message'])
                                except Exception as e:
                                    return ob['message']
                            elif type(ob) == type({}) and ob['msg']:
                                try:
                                    return exception_handler(ob['message'])
                                except Exception as e:
                                    return ob['msg']
                            return str(json.loads(exceptionObj.args[0]))
                        except Exception as e:
                            return str(exceptionObj.args[0])
            elif hasattr(exceptionObj, 'msg'):
                return exceptionObj.msg
            elif hasattr(exceptionObj, 'message'):
                return exceptionObj.message
        elif type(exceptionObj) == type(''):
            try:
                ob = json.loads(exceptionObj)
                if type(ob) == type({}):
                    if ob['message']:
                        return ob['message']
                    elif ob['msg']:
                        return ob['msg']
                    else:
                        return ob
            except Exception as e:
                return exceptionObj

    except Exception as e:
        return e
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
389267
def print_exception_formatted(type, value, tb):
    """"""

    tbtext = ''.join(traceback.format_exception(type, value, tb))
    lexer = get_lexer_by_name('pytb', stripall=True)
    formatter = TerminalFormatter()
    sys.stderr.write(highlight(tbtext, lexer, formatter))
81846
def format_error(err_type, err_value, err_trace=None):
    """"""
    if err_trace is None:
        err_parts = "".join(traceback.format_exception_only(err_type, err_value)).strip().split(": ", 1)
        if len(err_parts) == 1:
            err_name, err_msg = err_parts[0], ""
        else:
            err_name, err_msg = err_parts
        err_name = err_name.split(".")[-1]
        return err_name + ": " + err_msg
    else:
        return "".join(traceback.format_exception(err_type, err_value, err_trace)).strip()
679610
def exception_class(self, exception):
		""""""

		cls = type(exception)
		if cls.__module__ == 'exceptions':  # Built-in exception.
			return cls.__name__
		return "%s.%s" % (cls.__module__, cls.__name__)
795410
def ignore_exception(exception_class):
    """"""
    def _decorator(func):
        def newfunc(*args, **kwds):
            try:
                return func(*args, **kwds)
            except exception_class:
                pass
        return newfunc
    return _decorator
935065
def format_exception(exception):
    
    exception_lines = traceback.format_exception(*exception)
    # The lines returned from format_exception do not strictly contain
    # one line per element in the list (i.e. some elements have new
    # line characters in the middle). Normalize that oddity.
    lines = "".join(exception_lines).splitlines(True)
    return format_as_diagnostics(lines)
1160058
private void writeException(JsonGenerator generator, SentryException sentryException) throws IOException {
        generator.writeStartObject();
        generator.writeStringField(TYPE_PARAMETER, sentryException.getExceptionClassName());
        generator.writeStringField(VALUE_PARAMETER, sentryException.getExceptionMessage());
        generator.writeStringField(MODULE_PARAMETER, sentryException.getExceptionPackageName());
        generator.writeFieldName(STACKTRACE_PARAMETER);
        stackTraceInterfaceBinding.writeInterface(generator, sentryException.getStackTraceInterface());
        generator.writeEndObject();
    }
254430
def get_traceback_stxt():
        
        #/
        exc_cls, exc_obj, tb_obj = sys.exc_info()
        
        #/
        txt_s = traceback.format_exception(exc_cls, exc_obj, tb_obj)
    
        #/
        res = ''.join(txt_s)
    
        return res
886206
def _create_capture_exceptions(capture_decider: Callable[[BaseException], bool]) -> Callable:
        
        def wrapped(*args, **kwargs):
            result = CaptureWrapBuilder._capture_exceptions(*args, **kwargs)
            if result.exception is not None:
                if not capture_decider(result.exception):
                    raise result.exception
            return result

        return wrapped
1193079
public static <T> Callable<T> recover(Callable<T> callable, Function<Exception, T> exceptionHandler){
        return () -> {
            try{
                return callable.call();
            }catch (Exception exception){
                return exceptionHandler.apply(exception);
            }
        };
    }