traceback
– Traceback Module¶
This module provides a standard interface to print stack traces of programs. This is useful when you want to print stack traces under program control.
Available on these boards
- traceback.format_exception(etype: Type[BaseException], value: BaseException, tb: types.TracebackType, limit: int | None = None, chain: bool | None = True) None ¶
Format a stack trace and the exception information.
The arguments have the same meaning as the corresponding arguments to print_exception(). The return value is a list of strings, each ending in a newline and some containing internal newlines. When these lines are concatenated and printed, exactly the same text is printed as does print_exception().
Note
Setting
chain
will have no effect as chained exceptions are not yet implemented.- Paramètres:
etype (Type[BaseException]) – This is ignored and inferred from the type of
value
.value (BaseException) – The exception. Must be an instance of
BaseException
.tb (TracebackType) – The traceback object. If
None
, the traceback will not be printed.limit (int) – Print up to limit stack trace entries (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.chain (bool) – If
True
then chained exceptions will be printed (note: not yet implemented).
- traceback.print_exception(etype: Type[BaseException], value: BaseException, tb: types.TracebackType, limit: int | None = None, file: io.FileIO | None = None, chain: bool | None = True) None ¶
Prints exception information and stack trace entries.
Note
Setting
chain
will have no effect as chained exceptions are not yet implemented.- Paramètres:
etype (Type[BaseException]) – This is ignored and inferred from the type of
value
.value (BaseException) – The exception. Must be an instance of
BaseException
.tb (TracebackType) – The traceback object. If
None
, the traceback will not be printed.limit (int) – Print up to limit stack trace entries (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.file (io.FileIO) – If file is omitted or
None
, the output goes tosys.stderr
; otherwise it should be an open file or file-like object to receive the output.chain (bool) – If
True
then chained exceptions will be printed (note: not yet implemented).