电脑端,可以用traceback来找
mpy没有这个模块 咋办?
自己搞啊
翻WIKI 有个sys.print_exception函数
然后简单包装一下 完事儿 从不废话 都是干货
import io
import sys
class ERRINFO(io.IOBase):
def __init__(self):
self.info=''
self.err_line=''
self.linemark=False
def write(self,t):
s=t.decode()
if s!='\n':
if self.linemark:
self.err_line=s
self.linemark=False
self.info+=s
if s=='", line ':
self.linemark=True
tb=ERRINFO()
a=1
info=io.BytesIO()
try:
print(a/0)
except Exception as e:
print(e)
traceback=sys.print_exception(e,tb)
print(tb.info)
print(tb.err_line)
错误详细信息和行数都拿到了
说白了就是把repl打印的错误信息get了。。。