with open(xml_file, 'rb') as xf:
xdict = xmltodict.parse(xf)
try:
top = xdict ['top']
except MetaXmlError:
ok = False
traceback.print_exc()
except Exception as e:
traceback.print_exc()
ok = False
如果xml文件出现语法错误,ui界面就闪退了
File "c:python3\lib\site-packages\xmltodict.py", line 325, in parse
parser.ParseFile(xml)
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 31, column 12
通过“except Exception as e:”截获错误信息。也不行。
我的需求是:ui不闪退,截获这个语法错误信息,弹出报错对话框,提醒发生错误。
不能try catch 吗?