From a289f6302cfc84fa0e0c216a006517bfaf697a32 Mon Sep 17 00:00:00 2001 From: Shane Loretz Date: Thu, 31 May 2018 16:10:43 -0700 Subject: [PATCH] ParameterTypeException inherit from runtime_error --- rclcpp/include/rclcpp/parameter_value.hpp | 34 +++++++++-------------- rclcpp/src/rclcpp/parameter_value.cpp | 16 ----------- 2 files changed, 13 insertions(+), 37 deletions(-) diff --git a/rclcpp/include/rclcpp/parameter_value.hpp b/rclcpp/include/rclcpp/parameter_value.hpp index 9a6a737fc4..120f3619d1 100644 --- a/rclcpp/include/rclcpp/parameter_value.hpp +++ b/rclcpp/include/rclcpp/parameter_value.hpp @@ -42,25 +42,26 @@ enum ParameterType PARAMETER_STRING_ARRAY = rcl_interfaces::msg::ParameterType::PARAMETER_STRING_ARRAY, }; +/// Return the name of a parameter type +RCLCPP_PUBLIC +std::string +to_string(const ParameterType type); + +RCLCPP_PUBLIC +std::ostream & +operator<<(std::ostream & os, const ParameterType type); + /// Indicate the parameter type does not match the expected type. -class ParameterTypeException : public std::exception +class ParameterTypeException : public std::runtime_error { public: /// Construct an instance. /// \param[in] expected the expected parameter type. /// \param[in] actual the actual parameter type. RCLCPP_PUBLIC - ParameterTypeException(ParameterType expected, ParameterType actual); - - RCLCPP_PUBLIC - ~ParameterTypeException(); - - RCLCPP_PUBLIC - const char * - what() const noexcept override; - -private: - const std::string msg_; + ParameterTypeException(ParameterType expected, ParameterType actual) + : std::runtime_error("expected [" + to_string(expected) + "] got [" + to_string(actual) + "]") + {} }; /// Store the type and value of a parameter. @@ -308,15 +309,6 @@ RCLCPP_PUBLIC std::string to_string(const ParameterValue & type); -/// Return the name of a parameter type -RCLCPP_PUBLIC -std::string -to_string(const ParameterType type); - -RCLCPP_PUBLIC -std::ostream & -operator<<(std::ostream & os, const ParameterType type); - } // namespace rclcpp #endif // RCLCPP__PARAMETER_VALUE_HPP_ diff --git a/rclcpp/src/rclcpp/parameter_value.cpp b/rclcpp/src/rclcpp/parameter_value.cpp index c65da5bb3c..0bd5518ed0 100644 --- a/rclcpp/src/rclcpp/parameter_value.cpp +++ b/rclcpp/src/rclcpp/parameter_value.cpp @@ -18,7 +18,6 @@ #include using rclcpp::ParameterType; -using rclcpp::ParameterTypeException; using rclcpp::ParameterValue; std::string @@ -57,21 +56,6 @@ rclcpp::operator<<(std::ostream & os, const ParameterType type) return os; } -ParameterTypeException::ParameterTypeException(ParameterType expected, ParameterType actual) -: msg_("expected [" + rclcpp::to_string(expected) + "] got [" + rclcpp::to_string(actual) + "]") -{ -} - -ParameterTypeException::~ParameterTypeException() -{ -} - -const char * -ParameterTypeException::what() const throw () -{ - return msg_.c_str(); -} - template std::string array_to_string(