Improve "missing key" error message for AnyMap
This commit is contained in:
parent
b54ea8bd82
commit
24d1e86440
1 changed files with 10 additions and 6 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue