moveit2
The MoveIt Motion Planning Framework for ROS 2.
trajectory_generation_exceptions.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2019 Pilz GmbH & Co. KG
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Pilz GmbH & Co. KG nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 #pragma once
36 
37 #include <stdexcept>
38 #include <string>
39 
40 #include <moveit_msgs/msg/move_it_error_codes.hpp>
41 
43 {
47 class MoveItErrorCodeException : public std::runtime_error
48 {
49 public:
50  MoveItErrorCodeException(const std::string& msg);
51 
52 protected:
55  ~MoveItErrorCodeException() override = default;
56 
59 
60 public:
61  virtual const moveit_msgs::msg::MoveItErrorCodes::_val_type& getErrorCode() const = 0;
62 };
63 
64 template <moveit_msgs::msg::MoveItErrorCodes::_val_type ERROR_CODE = moveit_msgs::msg::MoveItErrorCodes::FAILURE>
66 {
67 public:
68  TemplatedMoveItErrorCodeException(const std::string& msg);
69  TemplatedMoveItErrorCodeException(const std::string& msg,
70  const moveit_msgs::msg::MoveItErrorCodes::_val_type& error_code);
71 
72 public:
73  const moveit_msgs::msg::MoveItErrorCodes::_val_type& getErrorCode() const override;
74 
75 private:
76  const moveit_msgs::msg::MoveItErrorCodes::_val_type error_code_{ ERROR_CODE };
77 };
78 
79 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
80 inline MoveItErrorCodeException::MoveItErrorCodeException(const std::string& msg) : std::runtime_error(msg)
81 {
82 }
83 
84 template <moveit_msgs::msg::MoveItErrorCodes::_val_type ERROR_CODE>
87 {
88 }
89 
90 template <moveit_msgs::msg::MoveItErrorCodes::_val_type ERROR_CODE>
92  const std::string& msg, const moveit_msgs::msg::MoveItErrorCodes::_val_type& error_code)
93  : MoveItErrorCodeException(msg), error_code_(error_code)
94 {
95 }
96 
97 template <moveit_msgs::msg::MoveItErrorCodes::_val_type ERROR_CODE>
98 inline const moveit_msgs::msg::MoveItErrorCodes::_val_type&
100 {
101  return error_code_;
102 }
103 
104 /*
105  * @brief Macro to automatically generate a derived class of
106  * the MoveItErrorCodeException class.
107  */
108 #define CREATE_MOVEIT_ERROR_CODE_EXCEPTION(EXCEPTION_CLASS_NAME, ERROR_CODE) \
109  class EXCEPTION_CLASS_NAME : public TemplatedMoveItErrorCodeException<ERROR_CODE> \
110  { \
111  public: \
112  EXCEPTION_CLASS_NAME(const std::string& msg) : TemplatedMoveItErrorCodeException(msg) \
113  { \
114  } \
115  \
116  EXCEPTION_CLASS_NAME(const std::string& msg, const moveit_msgs::msg::MoveItErrorCodes::_val_type& error_code) \
117  : TemplatedMoveItErrorCodeException(msg, error_code) \
118  { \
119  } \
120  }
121 
122 } // namespace pilz_industrial_motion_planner
Exception storing an moveit_msgs::msg::MoveItErrorCodes value.
MoveItErrorCodeException(const MoveItErrorCodeException &)=default
MoveItErrorCodeException & operator=(const MoveItErrorCodeException &)=default
virtual const moveit_msgs::msg::MoveItErrorCodes::_val_type & getErrorCode() const =0
MoveItErrorCodeException(MoveItErrorCodeException &&)=default
MoveItErrorCodeException & operator=(MoveItErrorCodeException &&)=default
const moveit_msgs::msg::MoveItErrorCodes::_val_type & getErrorCode() const override