From 94bb50ddc1df2414738409fb434430a3139b2ba7 Mon Sep 17 00:00:00 2001 From: Robert Haschke Date: Sat, 24 Feb 2018 12:25:00 +0100 Subject: [PATCH] fixup! PropertyMap: different exception types --- .../moveit/task_constructor/properties.h | 12 ++++++------ core/src/properties.cpp | 17 ++++++++++------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/core/include/moveit/task_constructor/properties.h b/core/include/moveit/task_constructor/properties.h index f0c4087a..f0c0282a 100644 --- a/core/include/moveit/task_constructor/properties.h +++ b/core/include/moveit/task_constructor/properties.h @@ -150,20 +150,20 @@ private: class Property::error : public std::runtime_error { protected: std::string property_name_; + std::string msg_; 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_; } - 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 { public: - explicit undeclared(const std::string& name); - explicit undeclared(const std::string& name, const std::string& msg); + explicit undeclared(const std::string& name, const std::string& msg = "undeclared"); }; class Property::undefined : public Property::error { public: - explicit undefined(const std::string& name); - explicit undefined(const std::string& name, const std::string& msg); + explicit undefined(const std::string& name, const std::string& msg = "undefined"); }; class Property::type_error : public Property::error { public: diff --git a/core/src/properties.cpp b/core/src/properties.cpp index d3e5894d..c922dc04 100644 --- a/core/src/properties.cpp +++ b/core/src/properties.cpp @@ -214,20 +214,24 @@ boost::any fromName(const PropertyMap& other, const std::string& other_name) } -Property::undeclared::undeclared(const std::string& name) - : undeclared(name, "Undeclared property: '" + name + "'") +Property::error::error(const std::string& msg) + : 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::error(msg) { 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::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)) {} - } // namespace task_constructor } // namespace moveit