Skip to content

Commit

Permalink
Adding Custom Unknown Type Error (ros2#2272)
Browse files Browse the repository at this point in the history
Signed-off-by: CursedRock17 <mtglucas1@gmail.com>
Co-authored-by: Christophe Bedard <bedard.christophe@gmail.com>
  • Loading branch information
2 people authored and Barry-Xu-2018 committed Jan 12, 2024
1 parent 9f89315 commit 646c488
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions rclcpp/include/rclcpp/exceptions/exceptions.hpp
Expand Up @@ -206,6 +206,14 @@ class UnknownROSArgsError : public std::runtime_error
const std::vector<std::string> unknown_ros_args;
};

/// Thrown when an unknown type is passed
class UnknownTypeError : public std::runtime_error
{
public:
explicit UnknownTypeError(const std::string & type)
: std::runtime_error("Unknown type: " + type) {}
};

/// Thrown when an invalid rclcpp::Event object or SharedPtr is encountered.
class InvalidEventError : public std::runtime_error
{
Expand Down
1 change: 1 addition & 0 deletions rclcpp/include/rclcpp/parameter_value.hpp
Expand Up @@ -24,6 +24,7 @@

#include "rcl_interfaces/msg/parameter_type.hpp"
#include "rcl_interfaces/msg/parameter_value.hpp"
#include "rclcpp/exceptions/exceptions.hpp"
#include "rclcpp/visibility_control.hpp"

namespace rclcpp
Expand Down
3 changes: 1 addition & 2 deletions rclcpp/src/rclcpp/parameter_value.cpp
Expand Up @@ -129,8 +129,7 @@ ParameterValue::ParameterValue(const rcl_interfaces::msg::ParameterValue & value
case PARAMETER_NOT_SET:
break;
default:
// TODO(wjwwood): use custom exception
throw std::runtime_error("Unknown type: " + std::to_string(value.type));
throw rclcpp::exceptions::UnknownTypeError(std::to_string(value.type));
}
}

Expand Down

0 comments on commit 646c488

Please sign in to comment.