Python-traceback:打印或检索堆栈回溯

Python 的 traceback 模块提供了一种标准方式来提取、格式化和打印程序的堆栈回溯。它模仿了Python解释器在打印堆栈跟踪时的行为。此模块包含 `print_exception` 和 `print_exc` 函数,用于在异常发生时显示详细信息和调用栈。`print_exception` 函数接受异常类型、值和跟踪信息,并可选地限制输出和链式异常处理。
摘要由CSDN通过智能技术生成

traceback docs
source code
This module provides a standard interface to extract, format and print stack traces of Python programs. It exactly mimics the behavior of the Python interpreter when it prints a stack trace. This is useful when you want to print stack traces under program control, such as in a “wrapper” around the interpreter.

traceback.print_exception(etype, value, tb, limit=None, file=None, chain=True)

Print exception information and stack trace entries from traceback object tb to file. This differs from print_tb() in the following ways:

if tb is not None, it prints a header Traceback (most recent call last):

it prints the exception etype and value after the stack trace

if type(value) is SyntaxError and value has the appropriate format, it prints the line where the syntax error occurred with a caret indicating the approximate position of the error.

The optional limit argument has the same meaning as for print_tb(). If chain is true (the default), then chained exceptions (the cause or context attributes of the exception) will be printed as well, like the interpreter itself does when printing an unhandled exception.

traceback.print_exc(limit=None, file=None, chain=True)

This is a shorthand for print_exception(*sys.exc_info(), limit, file, chain).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值