在下面的代码中,我希望防止显示内部错误回溯。(在lua中,等价物为error("info",2)
(。
这在Python中也可能吗?
def asd():
def efe(number = 2):
try:
number += 2
print(number)
except TypeError as e:
failed = True
# raise TypeError() # makes it even worse
if failed:
raise TypeError() # dont show internal stuff please
# raise TypeError().with_traceback() # i guess use this is the way
efe(number = "asd") # i want the end of Error Stack here
asd()
打印
Traceback (most recent call last):
File "main.py", line 15, in <module>
asd()
File "main.py", line 13, in asd
efe(number = "asd") # i want the end of Error Stack here
File "main.py", line 10, in efe
raise TypeError() # dont show internal stuff please
TypeError
我认为这在python中是不可能的。不过,您可以将一个"错误"作为纯文本print
输出。
编辑:尝试使用回溯模块格式化错误消息。