(self, *, chain=True)
Format the exception.

        If chain is not *True*, *__cause__* and *__context__* will not be formatted.

        The return value is a generator of strings, each ending in a newline and
        some containing internal newlines. `print_exception` is a wrapper around
        this method which just prints the lines to a file.

        The message indicating which exception occurred is always the last
        string in the output.
Format the exception.
Format the exception .
def format(self, *, chain=True):
        """Format the exception.

        If chain is not *True*, *__cause__* and *__context__* will not be formatted.

        The return value is a generator of strings, each ending in a newline and
        some containing internal newlines. `print_exception` is a wrapper around
        this method which just prints the lines to a file.

        The message indicating which exception occurred is always the last
        string in the output.
        """

        output = []
        exc = self
        while exc:
            if chain:
                if exc.__cause__ is not None:
                    chained_msg = _cause_message
                    chained_exc = exc.__cause__
                elif (exc.__context__  is not None and
                      not exc.__suppress_context__):
                    chained_msg = _context_message
                    chained_exc = exc.__context__
                else:
                    chained_msg = None
                    chained_exc = None

                output.append((chained_msg, exc))
                exc = chained_exc
            else:
                output.append((None, exc))
                exc = None

        for msg, exc in reversed(output):
            if msg is not None:
                yield msg
            if exc.stack:
                yield 'Traceback (most recent call last):\n'
                yield from exc.stack.format()
            yield from exc.format_exception_only()
def format ( self , * , chain = True ) : output = [ ] exc = self while exc : if chain : if exc . __cause__ is not None : chained_msg = _cause_message chained_exc = exc . __cause__ elif ( exc . __context__ is not None and not exc . __suppress_context__ ) : chained_msg = _context_message chained_exc = exc . __context__ else : chained_msg = None chained_exc = None output . append ( ( chained_msg , exc ) ) exc = chained_exc else : output . append ( ( None , exc ) ) exc = None for msg , exc in reversed ( output ) : if msg is not None : yield msg if exc . stack : yield 'Traceback (most recent call last):\n' yield from exc . stack . format ( ) yield from exc . format_exception_only ( )