better exception when boost regex cannot initialize ICU support - closes #2722

This commit is contained in:
Dane Springmeyer 2015-03-04 12:38:45 -08:00
parent 87e9c64fc4
commit 7f597233c9

View file

@ -40,18 +40,29 @@ expression_ptr parse_expression(std::string const& str)
auto node = std::make_shared<expr_node>();
std::string::const_iterator itr = str.begin();
std::string::const_iterator end = str.end();
try {
bool r = boost::spirit::qi::phrase_parse(itr, end, g, space, *node);
if (r && itr == end)
bool r = false;
try
{
r = boost::spirit::qi::phrase_parse(itr, end, g, space, *node);
}
catch (std::exception const& ex)
{
if (std::string("boost::spirit::qi::expectation_failure") == std::string(ex.what()))
{
return node;
// no need to show "boost::spirit::qi::expectation_failure" which is a std::runtime_error
throw config_error("Failed to parse expression: \"" + str + "\"");
}
else
{
throw config_error("Failed to parse expression: \"" + str + "\"");
// show "Could not initialize ICU resources" from boost::regex which is a std::runtime_error
throw config_error(std::string(ex.what()) + " for expression: \"" + str + "\"");
}
}
catch (std::exception const&) // boost::spirit::qi::expectation_failure
if (r && itr == end)
{
return node;
}
else
{
throw config_error("Failed to parse expression: \"" + str + "\"");
}