traceback

您所在的位置:网站首页 Python报错traceback traceback

traceback

2023-10-11 13:55| 来源: 网络整理| 查看: 265

Capture an exception for later rendering. limit, lookup_lines and capture_locals are as for the StackSummary class.

If compact is true, only data that is required by TracebackException’s format method is saved in the class attributes. In particular, the __context__ field is calculated only if __cause__ is None and __suppress_context__ is false.

Note that when locals are captured, they are also shown in the traceback.

max_group_width and max_group_depth control the formatting of exception groups (see BaseExceptionGroup). 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.

Changed in version 3.10: Added the compact parameter.

Changed in version 3.11: Added the max_group_width and max_group_depth parameters.

__cause__¶

A TracebackException of the original __cause__.

__context__¶

A TracebackException of the original __context__.

exceptions¶

If self represents an ExceptionGroup, this field holds a list of TracebackException instances representing the nested exceptions. Otherwise it is None.

New in version 3.11.

__suppress_context__¶

The __suppress_context__ value from the original exception.

__notes__¶

The __notes__ value from the original exception, or None if the exception does not have any notes. If it is not None is it formatted in the traceback after the exception string.

New in version 3.11.

stack¶

A StackSummary representing the traceback.

exc_type¶

The class of the original traceback.

filename¶

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

lineno¶

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

end_lineno¶

For syntax errors - the end line number where the error occurred. Can be None if not present.

New in version 3.10.

text¶

For syntax errors - the text where the error occurred.

offset¶

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

end_offset¶

For syntax errors - the end offset into the text where the error occurred. Can be None if not present.

New in version 3.10.

msg¶

For syntax errors - the compiler error message.

classmethod from_exception(exc, *, 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.

print(*, file=None, chain=True)¶

Print to file (default sys.stderr) the exception information returned by format().

New in version 3.11.

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.

format_exception_only()¶

Format the exception part of the traceback.

The return value is a generator of strings, each ending in a newline.

The generator emits the exception’s message followed by its notes (if it has any). The exception message is normally a single string; however, for SyntaxError exceptions, it consists of several lines that (when printed) display detailed information about where the syntax error occurred.

Changed in version 3.11: The exception’s notes are now included in the output.



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3