Improve "missing key" error message for AnyMap

This commit is contained in:
Ray Speth 2018-12-13 14:36:10 -05:00
parent b54ea8bd82
commit 24d1e86440

View file

@ -509,12 +509,16 @@ AnyValue& AnyMap::operator[](const std::string& key)
const AnyValue& AnyMap::at(const std::string& key) const
{
const auto& slash = boost::ifind_first(key, "/");
if (!slash) {
return m_data.at(key);
} else {
std::string head(key.begin(), slash.begin());
std::string tail(slash.end(), key.end());
return m_data.at(head).as<AnyMap>().at(tail);
try {
if (!slash) {
return m_data.at(key);
} else {
std::string head(key.begin(), slash.begin());
std::string tail(slash.end(), key.end());
return m_data.at(head).as<AnyMap>().at(tail);
}
} catch (std::out_of_range& err) {
throw CanteraError("AnyMap::at", "Key '{}' not found", key);
}
}