PyDocs

Nav

Python Runtime Services

TracebackException

  • TracebackException(exc_type, exc_value, exc_traceback, *, limit=None, lookup_lines=True, capture_locals=False, compact=False, max_group_width=15, max_group_depth=10)
An exception ready for rendering.

The traceback module captures enough attributes from the original exception
to this intermediary form to ensure that no references are held, while
still being able to fully print or format it.

max_group_width and max_group_depth control the formatting of exception
groups. The depth refers to the nesting level of the group, and the width
refers to the size of a single exception group's exceptions array. The
formatted output is truncated when either limit is exceeded.

Use `from_exception` to create TracebackException instances from exception
objects, or the constructor to create TracebackException instances from
individual components.

- :attr:`__cause__` A TracebackException of the original *__cause__*.
- :attr:`__context__` A TracebackException of the original *__context__*.
- :attr:`exceptions` For exception groups - a list of TracebackException
  instances for the nested *exceptions*.  ``None`` for other exceptions.
- :attr:`__suppress_context__` The *__suppress_context__* value from the
  original exception.
- :attr:`stack` A `StackSummary` representing the traceback.
- :attr:`exc_type` (deprecated) The class of the original traceback.
- :attr:`exc_type_str` String display of exc_type
- :attr:`filename` For syntax errors - the filename where the error
  occurred.
- :attr:`lineno` For syntax errors - the linenumber where the error
  occurred.
- :attr:`end_lineno` For syntax errors - the end linenumber where the error
  occurred. Can be `None` if not present.
- :attr:`text` For syntax errors - the text where the error
  occurred.
- :attr:`offset` For syntax errors - the offset into the text where the
  error occurred.
- :attr:`end_offset` For syntax errors - the end offset into the text where
  the error occurred. Can be `None` if not present.
- :attr:`msg` For syntax errors - the compiler error message.
Changed in 3.10, 3.11
  • 3.10: Added the compact parameter.
  • 3.11: Added the max_group_width and max_group_depth parameters.
Members of TracebackException

_

__cause__
A TracebackException of the original __cause__.
__context__
A TracebackException of the original __context__.
__notes__
The __notes__ value from the original exception, or None if the exception does not have any notes.
__suppress_context__
The __suppress_context__ value from the original exception.

e

end_lineno
For syntax errors - the end line number where the error occurred.
end_offset
For syntax errors - the end offset into the text where the error occurred.
exc_type
The class of the original exception.
exc_type_str
String display of the class of the original exception.
exceptions
If self represents an ExceptionGroup, this field holds a list of TracebackException instances representing the nested exceptions.

f

filename
For syntax errors - the file name where the error occurred.
format
Format the exception.
format_exception_only
Format the exception part of the traceback.
from_exception
Create a TracebackException from an exception.

l

lineno
For syntax errors - the line number where the error occurred.

m

msg
For syntax errors - the compiler error message.

o

offset
For syntax errors - the offset into the text where the error occurred.

p

print
Print the result of self.format(chain=chain) to 'file'.

s

stack
A StackSummary representing the traceback.

t

text
For syntax errors - the text where the error occurred.
0 Examples
No examples for traceback/TracebackException.
See Also
No see-alsos for traceback/TracebackException
0 Notes
No notes for TracebackException