traceback.TracebackException.format_exception_only()

format_exception_only() Format the exception part of the traceback. The return value is a generator of strings, each ending in a newline. Normally, the generator emits a single string; however, for SyntaxError exceptions, it emits several lines that (when printed) display detailed information about where the syntax error occurred. The message indicating which exception occurred is always the last string in the output.

traceback.TracebackException.format()

format(*, 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.

traceback.TracebackException.filename

filename For syntax errors - the file name where the error occurred.

traceback.TracebackException.exc_type

exc_type The class of the original traceback.

traceback.TracebackException

class traceback.TracebackException(exc_type, exc_value, exc_traceback, *, limit=None, lookup_lines=True, capture_locals=False) Capture an exception for later rendering. limit, lookup_lines and capture_locals are as for the StackSummary class. Note that when locals are captured, they are also shown in the traceback. __cause__ A TracebackException of the original __cause__. __context__ A TracebackException of the original __context__. __suppress_context__ The __suppress_context_

traceback.StackSummary.from_list()

classmethod from_list(a_list) Construct a StackSummary object from a supplied old-style list of tuples. Each tuple should be a 4-tuple with filename, lineno, name, line as the elements.

traceback.StackSummary.extract()

classmethod extract(frame_gen, *, limit=None, lookup_lines=True, capture_locals=False) Construct a StackSummary object from a frame generator (such as is returned by walk_stack() or walk_tb()). If limit is supplied, only this many frames are taken from frame_gen. If lookup_lines is False, the returned FrameSummary objects will not have read their lines in yet, making the cost of creating the StackSummary cheaper (which may be valuable if it may not actually get formatted). If capture_locals

traceback.StackSummary

class traceback.StackSummary classmethod extract(frame_gen, *, limit=None, lookup_lines=True, capture_locals=False) Construct a StackSummary object from a frame generator (such as is returned by walk_stack() or walk_tb()). If limit is supplied, only this many frames are taken from frame_gen. If lookup_lines is False, the returned FrameSummary objects will not have read their lines in yet, making the cost of creating the StackSummary cheaper (which may be valuable if it may not actually ge

traceback.print_tb()

traceback.print_tb(tb, limit=None, file=None) Print up to limit stack trace entries from traceback object tb (starting from the caller’s frame) if limit is positive. Otherwise, print the last abs(limit) entries. If limit is omitted or None, all entries are printed. If file is omitted or None, the output goes to sys.stderr; otherwise it should be an open file or file-like object to receive the output. Changed in version 3.5: Added negative limit support.

traceback.print_stack()

traceback.print_stack(f=None, limit=None, file=None) Print up to limit stack trace entries (starting from the invocation point) if limit is positive. Otherwise, print the last abs(limit) entries. If limit is omitted or None, all entries are printed. The optional f argument can be used to specify an alternate stack frame to start. The optional file argument has the same meaning as for print_tb(). Changed in version 3.5: Added negative limit support.