Skip to content
Snippets Groups Projects
Commit 29f266df authored by Christian Engwer's avatar Christian Engwer
Browse files

[parametertree] unify error messages

parent 83152426
No related branches found
No related tags found
No related merge requests found
......@@ -105,7 +105,8 @@ const ParameterTree& ParameterTree::sub(const std::string& key) const
else
{
if (subs_.count(key) == 0)
DUNE_THROW(Dune::RangeError, "SubTree '" << key << "' not found in ParameterTree (prefix " + prefix_ + ")");
DUNE_THROW(Dune::RangeError, "SubTree '" << key
<< "' not found in ParameterTree (prefix " + prefix_ + ")");
return subs_.find(key)->second;
}
}
......@@ -144,7 +145,8 @@ const std::string& ParameterTree::operator[] (const std::string& key) const
else
{
if (not (hasKey(key)))
DUNE_THROW(Dune::RangeError, "Key '" << key << "' not found in ParameterTree (prefix " + prefix_ + ")");
DUNE_THROW(Dune::RangeError, "Key '" << key
<< "' not found in ParameterTree (prefix " + prefix_ + ")");
return values_.find(key)->second;
}
}
......
......@@ -170,15 +170,15 @@ namespace Dune {
template <class T>
T get(const std::string& key) const {
if(not hasKey(key))
DUNE_THROW(RangeError, "Key '" << key << "' not found in parameter "
"file!");
DUNE_THROW(Dune::RangeError, "Key '" << key
<< "' not found in ParameterTree (prefix " + prefix_ + ")");
try {
return Parser<T>::parse((*this)[key]);
}
catch(const RangeError&) {
DUNE_THROW(RangeError, "Cannot parse value \"" <<
(*this)[key] << "\" for key \"" << key << "\" as a " <<
className<T>());
DUNE_THROW(RangeError, "Cannot parse value \"" << (*this)[key]
<< "\" for key \"" << prefix_ << "." << key
<< "\" as a " << className<T>());
}
}
......@@ -225,18 +225,19 @@ namespace Dune {
for(; it != end; ++it, ++n) {
s >> *it;
if(!s)
DUNE_THROW(RangeError, "Cannot parse value \"" << str << "\" as a "
"range of items of type " << className<Value>() << " "
"(" << n << " items were extracted successfully)");
DUNE_THROW(RangeError, "Cannot parse value \"" << str
<< "\" for key \"" << prefix_ << "." << key
<< "\" as a range of items of type " << className<Value>()
<< " (" << n << " items were extracted successfully)");
}
Value dummy;
s >> dummy;
// now extraction should have failed, and eof should be set
if(not s.fail() or not s.eof())
DUNE_THROW(RangeError, "Cannot parse value \"" << str << "\" as a "
"range of " << n << " items of type "
<< className<Value>() << " (more items than the range "
"can hold)");
DUNE_THROW(RangeError, "Cannot parse value \"" << str
<< "\" for key \"" << prefix_ << "." << key
<< "\" as a range of " << n << " items of type "
<< className<Value>() << " (more items than the range can hold)");
}
};
......@@ -249,14 +250,16 @@ namespace Dune {
s.imbue(std::locale::classic());
s >> val;
if(!s)
DUNE_THROW(RangeError, "Cannot parse value \"" << str << "\" as a " <<
className<T>());
DUNE_THROW(RangeError, "Cannot parse value \"" << str
<< (*this)[key] << "\" for key \"" << prefix_ << "." << key
<< "\" as a " << className<T>());
T dummy;
s >> dummy;
// now extraction should have failed, and eof should be set
if(not s.fail() or not s.eof())
DUNE_THROW(RangeError, "Cannot parse value \"" << str << "\" as a " <<
className<T>());
DUNE_THROW(RangeError, "Cannot parse value \"" << str
<< (*this)[key] << "\" for key \"" << prefix_ << "." << key
<< "\" as a " << className<T>());
return val;
}
};
......@@ -326,7 +329,9 @@ namespace Dune {
std::bitset<n> val;
std::vector<std::string> sub = split(str);
if (sub.size() != n)
DUNE_THROW(RangeError, "cannot parse bitset because of unmatching sizes");
DUNE_THROW(RangeError, "Cannot parse value \"" << str
<< (*this)[key] << "\" for key \"" << prefix_ << "." << key
<< "\" as a bitset because of unmatching sizes");
for (std::size_t i=0; i<n; ++i) {
val[i] = ParameterTree::Parser<bool>::parse(sub[i]);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment