Skip to content

Commit 65f0b70

Browse files
Adding Custom Unknown Type Error (#2272)
Signed-off-by: CursedRock17 <mtglucas1@gmail.com> Co-authored-by: Christophe Bedard <bedard.christophe@gmail.com>
1 parent 9b4b3da commit 65f0b70

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

rclcpp/include/rclcpp/exceptions/exceptions.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,14 @@ class UnknownROSArgsError : public std::runtime_error
206206
const std::vector<std::string> unknown_ros_args;
207207
};
208208

209+
/// Thrown when an unknown type is passed
210+
class UnknownTypeError : public std::runtime_error
211+
{
212+
public:
213+
explicit UnknownTypeError(const std::string & type)
214+
: std::runtime_error("Unknown type: " + type) {}
215+
};
216+
209217
/// Thrown when an invalid rclcpp::Event object or SharedPtr is encountered.
210218
class InvalidEventError : public std::runtime_error
211219
{

rclcpp/include/rclcpp/parameter_value.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include "rcl_interfaces/msg/parameter_type.hpp"
2626
#include "rcl_interfaces/msg/parameter_value.hpp"
27+
#include "rclcpp/exceptions/exceptions.hpp"
2728
#include "rclcpp/visibility_control.hpp"
2829

2930
namespace rclcpp

rclcpp/src/rclcpp/parameter_value.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ ParameterValue::ParameterValue(const rcl_interfaces::msg::ParameterValue & value
129129
case PARAMETER_NOT_SET:
130130
break;
131131
default:
132-
// TODO(wjwwood): use custom exception
133-
throw std::runtime_error("Unknown type: " + std::to_string(value.type));
132+
throw rclcpp::exceptions::UnknownTypeError(std::to_string(value.type));
134133
}
135134
}
136135

0 commit comments

Comments
 (0)