【发布时间】:2018-10-17 08:49:34
【问题描述】:
我有一个工具,用户可以通过 Qt Gui 选择 xml 来设置一些参数。问题是。当文件不是有效的 xml 文件时,我的工具就会崩溃。我在 Qt Creator 中收到以下错误:
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::property_tree::xml_parser::xml_parser_error> >'
what(): /home/path/to/Executable: expected <
10:40:44: The program has unexpectedly finished.
我可以检查 XML 是否有效,或者我可以捕获错误并执行其他操作而不是终止吗?
我想显示一条错误消息并取消解析。
我的阅读过程代码是:
#include <boost/property_tree/xml_parser.hpp>
#include <boost/property_tree/ptree.hpp>
...
using boost::property_tree::ptree;
ptree pt;
read_xml(filename, pt);
【问题讨论】:
-
这是一个 C++ 异常被抛出,因此你可以
catch它。