Skip to content

Commit 1714eee

Browse files
committed
✨ 添加新特性:堆栈信息输出
1 parent 1506957 commit 1714eee

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

small_bug_lab/trackback_per_line.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# coding: utf-8
2+
# @Time : 2021/3/27 8:43 AM
3+
4+
5+
from tool.log_ext import LogExt
6+
7+
log = LogExt().get_logger
8+
9+
10+
def division(a, b):
11+
return a / b
12+
13+
#
14+
# # 仅捕获原因
15+
# try:
16+
# d = division(1, 0)
17+
# except Exception as e:
18+
# log.error(f"error happened reason: {e}")
19+
20+
21+
# 打印堆栈信息
22+
# try:
23+
# d = division(1, 0)
24+
# except Exception as e:
25+
# log.exception(e)
26+
27+
28+
# 以每一行的形式打印出来
29+
import sys, traceback
30+
try:
31+
d = division(1, 0)
32+
except Exception as e:
33+
for e_info in traceback.format_exception(*sys.exc_info()):
34+
for _ in e_info[:-1].split("\n"):
35+
log.tback(_)

0 commit comments

Comments
 (0)