Skip to content

Commit

Permalink
ParameterTypeException inherit from runtime_error
Browse files Browse the repository at this point in the history
  • Loading branch information
sloretz committed May 31, 2018
1 parent f002629 commit a289f63
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 37 deletions.
34 changes: 13 additions & 21 deletions rclcpp/include/rclcpp/parameter_value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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_
16 changes: 0 additions & 16 deletions rclcpp/src/rclcpp/parameter_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include <vector>

using rclcpp::ParameterType;
using rclcpp::ParameterTypeException;
using rclcpp::ParameterValue;

std::string
Expand Down Expand Up @@ -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<typename ValType, typename PrintType = ValType>
std::string
array_to_string(
Expand Down

0 comments on commit a289f63

Please sign in to comment.