rclcpp  beta1
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 
39 
48 void
49 throw_from_rcl_error(rcl_ret_t ret, const std::string & prefix = "", bool reset_error = true);
50 
52 {
53 public:
55  RCLErrorBase(rcl_ret_t ret, const rcl_error_state_t * error_state);
56  virtual ~RCLErrorBase() {}
57 
61  size_t line;
63 };
64 
67 {
68 public:
70  RCLError(rcl_ret_t ret, const rcl_error_state_t * error_state, const std::string & prefix);
72  RCLError(const RCLErrorBase & base_exc, const std::string & prefix);
73 };
74 
76 class RCLBadAlloc : public RCLErrorBase, public std::bad_alloc
77 {
78 public:
80  RCLBadAlloc(rcl_ret_t ret, const rcl_error_state_t * error_state);
82  explicit RCLBadAlloc(const RCLErrorBase & base_exc);
83 };
84 
87 {
88 public:
91  rcl_ret_t ret,
92  const rcl_error_state_t * error_state,
93  const std::string & prefix);
95  RCLInvalidArgument(const RCLErrorBase & base_exc, const std::string & prefix);
96 };
97 
100 {
101 public:
103  : std::runtime_error("event is invalid") {}
104 };
105 
108 {
109 public:
111  : std::runtime_error("event already registered") {}
112 };
113 
114 } // namespace exceptions
115 } // namespace rclcpp
116 
117 #endif // RCLCPP__EXCEPTIONS_HPP_
void throw_from_rcl_error(rcl_ret_t ret, const std::string &prefix="", bool reset_error=true)
Throw a C++ std::exception which was created based on an rcl error.
size_t line
Definition: exceptions.hpp:61
rmw_ret_t rcl_ret_t
Definition: allocator_common.hpp:24
Thrown when an unregistered rclcpp::Event is encountered where a registered one was expected...
Definition: exceptions.hpp:107
InvalidNodeError()
Definition: exceptions.hpp:34
Definition: exceptions.hpp:51
std::string file
Definition: exceptions.hpp:60
virtual ~RCLErrorBase()
Definition: exceptions.hpp:56
#define RCLCPP_PUBLIC
Definition: visibility_control.hpp:50
Created when the ret is RCL_RET_INVALID_ARGUMENT.
Definition: exceptions.hpp:86
Created when the ret is RCL_RET_BAD_ALLOC.
Definition: exceptions.hpp:76
std::string message
Definition: exceptions.hpp:59
std::string formatted_message
Definition: exceptions.hpp:62
Thrown when a method is trying to use a node, but it is invalid.
Definition: exceptions.hpp:31
EventNotRegisteredError()
Definition: exceptions.hpp:110
InvalidEventError()
Definition: exceptions.hpp:102
Created when the return code does not match one of the other specialized exceptions.
Definition: exceptions.hpp:66
rcl_ret_t ret
Definition: exceptions.hpp:58
Thrown when an invalid rclcpp::Event object or SharedPtr is encountered.
Definition: exceptions.hpp:99