Skip to content
Snippets Groups Projects
Commit d5be34dc authored by Dr. Felix Tobias Schindler's avatar Dr. Felix Tobias Schindler
Browse files

[common.string] added some meaningfull error messages

parent 4c825d14
No related branches found
No related tags found
No related merge requests found
......@@ -174,17 +174,19 @@ private:
template <class S>
static S convert_from_string_safely(const std::string& str_in)
{
S s_out;
try {
s_out = Choose<S>::fromString(str_in);
return Choose<S>::fromString(str_in);
} catch (boost::bad_lexical_cast& e) {
DUNE_THROW(Exceptions::external_error,
"Error " << e.what() << " in boost while parsing the value " << str_in << ". \n");
"Error in boost while converting the string '" << str_in << "' to type '" << Typename<T>::value()
<< "':\n"
<< e.what());
} catch (std::exception& e) {
DUNE_THROW(Exceptions::external_error,
"Error " << e.what() << " in the stl while parsing the value " << str_in << ". \n");
"Error in the stl while converting the string '" << str_in << "' to type '" << Typename<T>::value()
<< "':\n"
<< e.what());
}
return s_out;
} // ... convert_from_string_safely(...)
protected:
......@@ -244,7 +246,6 @@ protected:
}
} // ... get_matrix_from_string(...)
template <class VectorType, class S>
static VectorType get_vector_from_string(std::string vector_str, const size_t size)
{
......@@ -289,7 +290,19 @@ public:
{
assert(rows == 0);
assert(cols == 0);
return boost::lexical_cast<ReturnType, std::string>(s);
try {
return boost::lexical_cast<ReturnType, std::string>(s);
} catch (boost::bad_lexical_cast& e) {
DUNE_THROW(Exceptions::external_error,
"Error in boost while converting the string '" << s << "' to type '" << Typename<ReturnType>::value()
<< "':\n"
<< e.what());
} catch (std::exception& e) {
DUNE_THROW(Exceptions::external_error,
"Error in the stl while converting the string '" << s << "' to type '" << Typename<ReturnType>::value()
<< "':\n"
<< e.what());
}
}
}; // ... Choose < ReturnType >
......@@ -311,8 +324,11 @@ public:
else {
try {
return char(stoi(s));
} catch (std::invalid_argument) {
DUNE_THROW(Stuff::Exceptions::wrong_input_given, "Failed to convert string to char");
} catch (std::invalid_argument& e) {
DUNE_THROW(Stuff::Exceptions::wrong_input_given,
"Error in the stl while converting the string '" << s << "' to type '" << Typename<char>::value()
<< "':\n"
<< e.what());
}
}
} // ... fromString(...)
......
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