Python程序的traceback信息均来源于一个叫做traceback object的对象。
sys.exc_info()获取了当前处理的exception的相关信息。
traceback.print_tb(tb[, limit[, file]])
traceback.print_exception(etype, value, tb[, limit[, file]])
traceback.print_exc([limit[, file]])
import sys import traceback def func1(): raise NameError("--func1 exception--") def main(): try: func1() except Exception as e: # 异常的类型, 异常的value值,traceback object. exc_type, exc_value, exc_traceback_obj = sys.exc_info() traceback.print_tb(exc_traceback_obj) traceback.print_exception(exc_type, exc_value, exc_traceback_obj, limit=2, file=sys.stdout) traceback.print_exc(limit=1, file=sys.stdout) if __name__ == ‘__main__‘: main()
原文链接:https://www.jianshu.com/p/a8cb5375171a
原文:https://www.cnblogs.com/Mint-diary/p/14451793.html