Skip to content

Commit

Permalink
Adding Custom Unknown Type Error
Browse files Browse the repository at this point in the history
Signed-off-by: CursedRock17 <mtglucas1@gmail.com>
  • Loading branch information
CursedRock17 committed Aug 14, 2023
1 parent 9b4b3da commit 91c7662
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
Original file line number Diff line number Diff line change
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 UnkownTypeError : 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
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "rcl_interfaces/msg/parameter_type.hpp"
#include "rcl_interfaces/msg/parameter_value.hpp"
#include "rclcpp/visibility_control.hpp"
#include "rclcpp/exceptions/exceptions.hpp"

namespace rclcpp
{
Expand Down
3 changes: 1 addition & 2 deletions rclcpp/src/rclcpp/parameter_value.cpp
Original file line number Diff line number Diff line change
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));
UnknownTypeError(std::to_string(value.type));
}
}

Expand Down

0 comments on commit 91c7662

Please sign in to comment.