rclcpp  master
C++ ROS Client Library API
exceptions.hpp
Go to the documentation of this file.
1 // Copyright 2016 Open Source Robotics Foundation, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef RCLCPP__EXCEPTIONS__EXCEPTIONS_HPP_
16 #define RCLCPP__EXCEPTIONS__EXCEPTIONS_HPP_
17 
18 #include <stdexcept>
19 #include <string>
20 #include <vector>
21 
22 #include "rcl/error_handling.h"
23 #include "rcl/types.h"
25 
26 #include "rcpputils/join.hpp"
27 
28 namespace rclcpp
29 {
30 namespace exceptions
31 {
32 
35 {
36 public:
38  : std::runtime_error("node is invalid") {}
39 };
40 
43 {
44 public:
46  const char * name_type_,
47  const char * name_,
48  const char * error_msg_,
49  size_t invalid_index_)
50  : std::invalid_argument(format_error(name_type_, name_, error_msg_, invalid_index_)),
51  name_type(name_type_), name(name_), error_msg(error_msg_), invalid_index(invalid_index_)
52  {}
53 
54  static std::string
56  const char * name_type,
57  const char * name,
58  const char * error_msg,
59  size_t invalid_index);
60 
64  const size_t invalid_index;
65 };
66 
69 {
70 public:
71  InvalidNodeNameError(const char * node_name, const char * error_msg, size_t invalid_index)
72  : NameValidationError("node name", node_name, error_msg, invalid_index)
73  {}
74 };
75 
78 {
79 public:
80  InvalidNamespaceError(const char * namespace_, const char * error_msg, size_t invalid_index)
81  : NameValidationError("namespace", namespace_, error_msg, invalid_index)
82  {}
83 };
84 
87 {
88 public:
89  InvalidTopicNameError(const char * namespace_, const char * error_msg, size_t invalid_index)
90  : NameValidationError("topic name", namespace_, error_msg, invalid_index)
91  {}
92 };
93 
96 {
97 public:
98  InvalidServiceNameError(const char * namespace_, const char * error_msg, size_t invalid_index)
99  : NameValidationError("service name", namespace_, error_msg, invalid_index)
100  {}
101 };
102 
104 {
105 public:
107  : std::runtime_error("This code is unimplemented.") {}
108  explicit UnimplementedError(const std::string & msg)
109  : std::runtime_error(msg) {}
110 };
111 
113 
125 /* *INDENT-OFF* */ // Uncrustify cannot yet understand [[noreturn]] properly
127 void
128 throw_from_rcl_error [[noreturn]] (
129  rcl_ret_t ret,
130  const std::string & prefix = "",
131  const rcl_error_state_t * error_state = nullptr,
132  void (* reset_error)() = rcl_reset_error);
133 /* *INDENT-ON* */
134 
136 {
137 public:
139  RCLErrorBase(rcl_ret_t ret, const rcl_error_state_t * error_state);
140  virtual ~RCLErrorBase() {}
141 
145  size_t line;
147 };
148 
151 {
152 public:
154  RCLError(rcl_ret_t ret, const rcl_error_state_t * error_state, const std::string & prefix);
156  RCLError(const RCLErrorBase & base_exc, const std::string & prefix);
157 };
158 
161 {
162 public:
164  RCLBadAlloc(rcl_ret_t ret, const rcl_error_state_t * error_state);
166  explicit RCLBadAlloc(const RCLErrorBase & base_exc);
167 };
168 
171 {
172 public:
175  rcl_ret_t ret,
176  const rcl_error_state_t * error_state,
177  const std::string & prefix);
179  RCLInvalidArgument(const RCLErrorBase & base_exc, const std::string & prefix);
180 };
181 
184 {
185 public:
188  rcl_ret_t ret, const rcl_error_state_t * error_state, const std::string & prefix);
190  RCLInvalidROSArgsError(const RCLErrorBase & base_exc, const std::string & prefix);
191 };
192 
195 {
196 public:
197  explicit UnknownROSArgsError(std::vector<std::string> && unknown_ros_args_in)
198  : std::runtime_error(
199  "found unknown ROS arguments: '" + rcpputils::join(unknown_ros_args_in, "', '") + "'"),
200  unknown_ros_args(unknown_ros_args_in)
201  {
202  }
203 
205 };
206 
209 {
210 public:
212  : std::runtime_error("event is invalid") {}
213 };
214 
217 {
218 public:
220  : std::runtime_error("event already registered") {}
221 };
222 
225 {
226 public:
227  // Inherit constructors from runtime_error.
229 };
230 
233 {
234  // Inherit constructors from runtime_error.
236 };
237 
239 
244 {
245 public:
247 
253  : std::runtime_error("parameter '" + name + "' has invalid type: " + message)
254  {}
255 };
256 
259 {
260  // Inherit constructors from runtime_error.
262 };
263 
266 {
267  // Inherit constructors from runtime_error.
269 };
270 
273 {
274  // Inherit constructors from runtime_error.
276 };
277 
280 {
281  // Inherit constructors from runtime_error.
283 };
284 
287 {
288 public:
290 
295  : std::runtime_error("parameter '" + name + "' requires an user provided parameter override")
296  {}
297 };
298 
301 {
302  // Inherit constructors from runtime_error.
304 };
305 
308 {
309  // Inherit constructors from runtime_error.
311 };
312 
313 } // namespace exceptions
314 } // namespace rclcpp
315 
316 #endif // RCLCPP__EXCEPTIONS__EXCEPTIONS_HPP_
rclcpp::exceptions::RCLErrorBase::line
size_t line
Definition: exceptions.hpp:145
rclcpp::exceptions::RCLErrorBase::RCLErrorBase
RCLErrorBase(rcl_ret_t ret, const rcl_error_state_t *error_state)
rclcpp::exceptions::NameValidationError
Thrown when a any kind of name (node, namespace, topic, etc.) is invalid.
Definition: exceptions.hpp:42
rclcpp::exceptions::EventNotRegisteredError::EventNotRegisteredError
EventNotRegisteredError()
Definition: exceptions.hpp:219
rclcpp::exceptions::InvalidParametersException
Thrown if passed parameters are inconsistent or invalid.
Definition: exceptions.hpp:224
std::string
std::bad_alloc
rcl_ret_t
rmw_ret_t rcl_ret_t
rclcpp::exceptions::InvalidNamespaceError
Thrown when a node namespace is invalid.
Definition: exceptions.hpp:77
rclcpp::exceptions::RCLInvalidROSArgsError::RCLInvalidROSArgsError
RCLInvalidROSArgsError(rcl_ret_t ret, const rcl_error_state_t *error_state, const std::string &prefix)
rclcpp::exceptions::RCLError
Created when the return code does not match one of the other specialized exceptions.
Definition: exceptions.hpp:150
rclcpp::exceptions::QoSCheckCompatibleException
Thrown if a QoS compatibility check fails.
Definition: exceptions.hpp:307
rclcpp::exceptions::InvalidNodeNameError
Thrown when a node name is invalid.
Definition: exceptions.hpp:68
rclcpp::exceptions::EventNotRegisteredError
Thrown when an unregistered rclcpp::Event is encountered where a registered one was expected.
Definition: exceptions.hpp:216
rclcpp::exceptions::UnimplementedError
Definition: exceptions.hpp:103
std::vector< std::string >
rclcpp::exceptions::NoParameterOverrideProvided::NoParameterOverrideProvided
NoParameterOverrideProvided(const std::string &name)
Construct an instance.
Definition: exceptions.hpp:294
rclcpp::exceptions::InvalidServiceNameError::InvalidServiceNameError
InvalidServiceNameError(const char *namespace_, const char *error_msg, size_t invalid_index)
Definition: exceptions.hpp:98
rclcpp::exceptions::InvalidTopicNameError::InvalidTopicNameError
InvalidTopicNameError(const char *namespace_, const char *error_msg, size_t invalid_index)
Definition: exceptions.hpp:89
rclcpp::exceptions::UnknownROSArgsError::unknown_ros_args
const std::vector< std::string > unknown_ros_args
Definition: exceptions.hpp:204
rclcpp::exceptions::InvalidTopicNameError
Thrown when a topic name is invalid.
Definition: exceptions.hpp:86
rclcpp::exceptions::RCLErrorBase
Definition: exceptions.hpp:135
rclcpp
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
RCLCPP_PUBLIC
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
rclcpp::exceptions::RCLErrorBase::~RCLErrorBase
virtual ~RCLErrorBase()
Definition: exceptions.hpp:140
rclcpp::exceptions::InvalidNamespaceError::InvalidNamespaceError
InvalidNamespaceError(const char *namespace_, const char *error_msg, size_t invalid_index)
Definition: exceptions.hpp:80
rclcpp::exceptions::UnknownROSArgsError::UnknownROSArgsError
UnknownROSArgsError(std::vector< std::string > &&unknown_ros_args_in)
Definition: exceptions.hpp:197
rclcpp::exceptions::InvalidServiceNameError
Thrown when a service name is invalid.
Definition: exceptions.hpp:95
rclcpp::exceptions::RCLBadAlloc::RCLBadAlloc
RCLBadAlloc(rcl_ret_t ret, const rcl_error_state_t *error_state)
rclcpp::exceptions::InvalidEventError
Thrown when an invalid rclcpp::Event object or SharedPtr is encountered.
Definition: exceptions.hpp:208
rclcpp::exceptions::ParameterImmutableException
Thrown if parameter is immutable and therefore cannot be undeclared.
Definition: exceptions.hpp:272
rclcpp::exceptions::InvalidParameterValueException
Thrown if passed parameter value is invalid.
Definition: exceptions.hpp:232
rclcpp::exceptions::ParameterAlreadyDeclaredException
Thrown if parameter is already declared.
Definition: exceptions.hpp:258
rclcpp::exceptions::RCLInvalidArgument::RCLInvalidArgument
RCLInvalidArgument(rcl_ret_t ret, const rcl_error_state_t *error_state, const std::string &prefix)
rclcpp::exceptions::RCLErrorBase::formatted_message
std::string formatted_message
Definition: exceptions.hpp:146
rclcpp::exceptions::NameValidationError::error_msg
const std::string error_msg
Definition: exceptions.hpp:63
rclcpp::exceptions::ParameterModifiedInCallbackException
Thrown if parameter is modified while in a set callback.
Definition: exceptions.hpp:279
rclcpp::exceptions::InvalidNodeNameError::InvalidNodeNameError
InvalidNodeNameError(const char *node_name, const char *error_msg, size_t invalid_index)
Definition: exceptions.hpp:71
rclcpp::exceptions::RCLErrorBase::message
std::string message
Definition: exceptions.hpp:143
std::runtime_error
std::invalid_argument
rclcpp::exceptions::UnimplementedError::UnimplementedError
UnimplementedError()
Definition: exceptions.hpp:106
rclcpp::exceptions::NameValidationError::name
const std::string name
Definition: exceptions.hpp:62
rclcpp::exceptions::NameValidationError::name_type
const std::string name_type
Definition: exceptions.hpp:61
rclcpp::exceptions::RCLError::RCLError
RCLError(rcl_ret_t ret, const rcl_error_state_t *error_state, const std::string &prefix)
rclcpp::exceptions::NoParameterOverrideProvided
Thrown when a parameter override wasn't provided and one was required.
Definition: exceptions.hpp:286
rclcpp::exceptions::RCLErrorBase::ret
rcl_ret_t ret
Definition: exceptions.hpp:142
rclcpp::exceptions::RCLErrorBase::file
std::string file
Definition: exceptions.hpp:144
visibility_control.hpp
std
rclcpp::exceptions::InvalidEventError::InvalidEventError
InvalidEventError()
Definition: exceptions.hpp:211
rclcpp::exceptions::RCLInvalidROSArgsError
Created when the ret is RCL_RET_INVALID_ROS_ARGS.
Definition: exceptions.hpp:183
rclcpp::exceptions::UnknownROSArgsError
Thrown when unparsed ROS specific arguments are found.
Definition: exceptions.hpp:194
rclcpp::exceptions::UnimplementedError::UnimplementedError
UnimplementedError(const std::string &msg)
Definition: exceptions.hpp:108
rclcpp::exceptions::throw_from_rcl_error
void throw_from_rcl_error(rcl_ret_t ret, const std::string &prefix="", const rcl_error_state_t *error_state=nullptr, void(*reset_error)()=rcl_reset_error)
Throw a C++ std::exception which was created based on an rcl error.
rclcpp::exceptions::InvalidQosOverridesException
Thrown if the QoS overrides provided aren't valid.
Definition: exceptions.hpp:300
rclcpp::exceptions::InvalidParameterTypeException
Thrown if requested parameter type is invalid.
Definition: exceptions.hpp:243
rclcpp::exceptions::NameValidationError::invalid_index
const size_t invalid_index
Definition: exceptions.hpp:64
rclcpp::exceptions::ParameterNotDeclaredException
Thrown if parameter is not declared, e.g. either set or get was called without first declaring.
Definition: exceptions.hpp:265
types.h
rclcpp::exceptions::InvalidNodeError::InvalidNodeError
InvalidNodeError()
Definition: exceptions.hpp:37
rclcpp::exceptions::NameValidationError::format_error
static std::string format_error(const char *name_type, const char *name, const char *error_msg, size_t invalid_index)
rclcpp::exceptions::RCLInvalidArgument
Created when the ret is RCL_RET_INVALID_ARGUMENT.
Definition: exceptions.hpp:170
rclcpp::exceptions::NameValidationError::NameValidationError
NameValidationError(const char *name_type_, const char *name_, const char *error_msg_, size_t invalid_index_)
Definition: exceptions.hpp:45
rclcpp::exceptions::InvalidParameterTypeException::InvalidParameterTypeException
InvalidParameterTypeException(const std::string &name, const std::string message)
Construct an instance.
Definition: exceptions.hpp:252
rclcpp::exceptions::InvalidNodeError
Thrown when a method is trying to use a node, but it is invalid.
Definition: exceptions.hpp:34
rclcpp::exceptions::RCLBadAlloc
Created when the ret is RCL_RET_BAD_ALLOC.
Definition: exceptions.hpp:160