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_HPP_
16 #define RCLCPP__EXCEPTIONS_HPP_
17 
18 #include <stdexcept>
19 #include <string>
20 
21 #include "rcl/error_handling.h"
22 #include "rcl/types.h"
24 
25 namespace rclcpp
26 {
27 namespace exceptions
28 {
29 
32 {
33 public:
35  : std::runtime_error("node is invalid") {}
36 };
37 
40 {
41 public:
43  const char * name_type_,
44  const char * name_,
45  const char * error_msg_,
46  size_t invalid_index_)
47  : std::invalid_argument(format_error(name_type_, name_, error_msg_, invalid_index_)),
48  name_type(name_type_), name(name_), error_msg(error_msg_), invalid_index(invalid_index_)
49  {}
50 
51  static std::string
52  format_error(
53  const char * name_type,
54  const char * name,
55  const char * error_msg,
56  size_t invalid_index);
57 
61  const size_t invalid_index;
62 };
63 
66 {
67 public:
68  InvalidNodeNameError(const char * node_name, const char * error_msg, size_t invalid_index)
69  : NameValidationError("node name", node_name, error_msg, invalid_index)
70  {}
71 };
72 
75 {
76 public:
77  InvalidNamespaceError(const char * namespace_, const char * error_msg, size_t invalid_index)
78  : NameValidationError("namespace", namespace_, error_msg, invalid_index)
79  {}
80 };
81 
84 {
85 public:
86  InvalidTopicNameError(const char * namespace_, const char * error_msg, size_t invalid_index)
87  : NameValidationError("topic name", namespace_, error_msg, invalid_index)
88  {}
89 };
90 
93 {
94 public:
95  InvalidServiceNameError(const char * namespace_, const char * error_msg, size_t invalid_index)
96  : NameValidationError("service name", namespace_, error_msg, invalid_index)
97  {}
98 };
99 
101 
113 /* *INDENT-OFF* */ // Uncrustify cannot yet understand [[noreturn]] properly
115 void
116 throw_from_rcl_error [[noreturn]] (
117  rcl_ret_t ret,
118  const std::string & prefix = "",
119  const rcl_error_state_t * error_state = nullptr,
120  void (* reset_error)() = rcl_reset_error);
121 /* *INDENT-ON* */
122 
124 {
125 public:
127  RCLErrorBase(rcl_ret_t ret, const rcl_error_state_t * error_state);
128  virtual ~RCLErrorBase() {}
129 
133  size_t line;
135 };
136 
139 {
140 public:
142  RCLError(rcl_ret_t ret, const rcl_error_state_t * error_state, const std::string & prefix);
144  RCLError(const RCLErrorBase & base_exc, const std::string & prefix);
145 };
146 
149 {
150 public:
152  RCLBadAlloc(rcl_ret_t ret, const rcl_error_state_t * error_state);
154  explicit RCLBadAlloc(const RCLErrorBase & base_exc);
155 };
156 
159 {
160 public:
163  rcl_ret_t ret,
164  const rcl_error_state_t * error_state,
165  const std::string & prefix);
167  RCLInvalidArgument(const RCLErrorBase & base_exc, const std::string & prefix);
168 };
169 
172 {
173 public:
175  : std::runtime_error("event is invalid") {}
176 };
177 
180 {
181 public:
183  : std::runtime_error("event already registered") {}
184 };
185 
188 {
189 public:
190  // Inherit constructors from runtime_error.
192 };
193 
196 {
197  // Inherit constructors from runtime_error.
199 };
200 
203 {
204  // Inherit constructors from runtime_error.
206 };
207 
210 {
211  // Inherit constructors from runtime_error.
213 };
214 
217 {
218  // Inherit constructors from runtime_error.
220 };
221 
222 } // namespace exceptions
223 } // namespace rclcpp
224 
225 #endif // RCLCPP__EXCEPTIONS_HPP_
Created when the return code does not match one of the other specialized exceptions.
Definition: exceptions.hpp:138
Created when the ret is RCL_RET_INVALID_ARGUMENT.
Definition: exceptions.hpp:158
InvalidNodeError()
Definition: exceptions.hpp:34
Thrown when a any kind of name (node, namespace, topic, etc.) is invalid.
Definition: exceptions.hpp:39
#define rcl_reset_error
rmw_ret_t rcl_ret_t
Thrown if parameter is already declared.
Definition: exceptions.hpp:202
Thrown if passed parameters are inconsistent or invalid.
Definition: exceptions.hpp:187
Thrown when a topic name is invalid.
Definition: exceptions.hpp:83
EventNotRegisteredError()
Definition: exceptions.hpp:182
Thrown when an unregistered rclcpp::Event is encountered where a registered one was expected...
Definition: exceptions.hpp:179
Thrown when an invalid rclcpp::Event object or SharedPtr is encountered.
Definition: exceptions.hpp:171
Thrown when a service name is invalid.
Definition: exceptions.hpp:92
InvalidEventError()
Definition: exceptions.hpp:174
This header provides the get_node_topics_interface() template function.
Definition: allocator_common.hpp:24
std::string file
Definition: exceptions.hpp:132
InvalidNodeNameError(const char *node_name, const char *error_msg, size_t invalid_index)
Definition: exceptions.hpp:68
Thrown when a method is trying to use a node, but it is invalid.
Definition: exceptions.hpp:31
rcl_ret_t ret
Definition: exceptions.hpp:130
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.
InvalidNamespaceError(const char *namespace_, const char *error_msg, size_t invalid_index)
Definition: exceptions.hpp:77
Definition: exceptions.hpp:123
const std::string name_type
Definition: exceptions.hpp:58
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
const size_t invalid_index
Definition: exceptions.hpp:61
Thrown if parameter is not declared, e.g. either set or get was called without first declaring...
Definition: exceptions.hpp:209
const std::string error_msg
Definition: exceptions.hpp:60
InvalidTopicNameError(const char *namespace_, const char *error_msg, size_t invalid_index)
Definition: exceptions.hpp:86
std::string message
Definition: exceptions.hpp:131
Created when the ret is RCL_RET_BAD_ALLOC.
Definition: exceptions.hpp:148
Thrown when a node namespace is invalid.
Definition: exceptions.hpp:74
Thrown if parameter is immutable and therefore cannot be undeclared.
Definition: exceptions.hpp:216
NameValidationError(const char *name_type_, const char *name_, const char *error_msg_, size_t invalid_index_)
Definition: exceptions.hpp:42
InvalidServiceNameError(const char *namespace_, const char *error_msg, size_t invalid_index)
Definition: exceptions.hpp:95
size_t line
Definition: exceptions.hpp:133
std::string formatted_message
Definition: exceptions.hpp:134
const std::string name
Definition: exceptions.hpp:59
virtual ~RCLErrorBase()
Definition: exceptions.hpp:128
Thrown if passed parameter value is invalid.
Definition: exceptions.hpp:195
Thrown when a node name is invalid.
Definition: exceptions.hpp:65