fixup! PropertyMap: different exception types

This commit is contained in:
Robert Haschke 2018-02-24 12:25:00 +01:00
parent 30de5e1a8c
commit 94bb50ddc1
2 changed files with 16 additions and 13 deletions

View File

@ -150,20 +150,20 @@ private:
class Property::error : public std::runtime_error { class Property::error : public std::runtime_error {
protected: protected:
std::string property_name_; std::string property_name_;
std::string msg_;
public: public:
explicit error(const std::string& msg) : std::runtime_error(msg) {} explicit error(const std::string& msg);
const std::string& name() const { return property_name_; } const std::string& name() const { return property_name_; }
void setName(const std::string& name) { property_name_ = name; } void setName(const std::string& name);
const char* what() const noexcept override { return msg_.c_str(); }
}; };
class Property::undeclared : public Property::error { class Property::undeclared : public Property::error {
public: public:
explicit undeclared(const std::string& name); explicit undeclared(const std::string& name, const std::string& msg = "undeclared");
explicit undeclared(const std::string& name, const std::string& msg);
}; };
class Property::undefined : public Property::error { class Property::undefined : public Property::error {
public: public:
explicit undefined(const std::string& name); explicit undefined(const std::string& name, const std::string& msg = "undefined");
explicit undefined(const std::string& name, const std::string& msg);
}; };
class Property::type_error : public Property::error { class Property::type_error : public Property::error {
public: public:

View File

@ -214,20 +214,24 @@ boost::any fromName(const PropertyMap& other, const std::string& other_name)
} }
Property::undeclared::undeclared(const std::string& name) Property::error::error(const std::string& msg)
: undeclared(name, "Undeclared property: '" + name + "'") : std::runtime_error("Property: " + msg)
, msg_(msg)
{} {}
void Property::error::setName(const std::string& name)
{
property_name_ = name;
// compose message from property name and runtime_errors' msg
msg_ = "Property '" + name + "': " + std::runtime_error::what();
}
Property::undeclared::undeclared(const std::string& name, const std::string& msg) Property::undeclared::undeclared(const std::string& name, const std::string& msg)
: Property::error(msg) : Property::error(msg)
{ {
setName(name); setName(name);
} }
Property::undefined::undefined(const std::string& name)
: undefined(name, "Undefined property: '" + name + "'")
{}
Property::undefined::undefined(const std::string& name, const std::string& msg) Property::undefined::undefined(const std::string& name, const std::string& msg)
: Property::error(msg) : Property::error(msg)
{ {
@ -239,6 +243,5 @@ Property::type_error::type_error(const std::string& current_type, const std::str
: Property::error(boost::str(type_error_fmt % current_type % declared_type)) : Property::error(boost::str(type_error_fmt % current_type % declared_type))
{} {}
} // namespace task_constructor } // namespace task_constructor
} // namespace moveit } // namespace moveit