exceptions.h
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // Copyright 2019 FZI Forschungszentrum Informatik
5 // Created on behalf of Universal Robots A/S
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 // -- END LICENSE BLOCK ------------------------------------------------
19 
20 //----------------------------------------------------------------------
27 //----------------------------------------------------------------------
28 
29 #ifndef UR_CLIENT_LIBRARY_EXCEPTIONS_H_INCLUDED
30 #define UR_CLIENT_LIBRARY_EXCEPTIONS_H_INCLUDED
31 
32 #include <chrono>
33 #include <stdexcept>
34 #include <sstream>
35 #include "ur/version_information.h"
36 
37 #ifdef _WIN32
38 # define NOMINMAX
39 # define WIN32_LEAN_AND_MEAN
40 # include <WinSock2.h>
41 # ifdef ERROR
42 # undef ERROR
43 # endif // ERROR
44 #else
45 # include <sys/time.h>
46 #endif
47 
48 namespace urcl
49 {
53 class UrException : virtual public std::runtime_error
54 {
55 public:
56  explicit UrException() : std::runtime_error("")
57  {
58  }
59  explicit UrException(const std::string& what_arg) : std::runtime_error(what_arg)
60  {
61  }
62  explicit UrException(const char* what_arg) : std::runtime_error(what_arg)
63  {
64  }
65 
66  virtual ~UrException() = default;
67 
68 private:
69  /* data */
70 };
71 
76 {
77 public:
78  explicit VersionMismatch() : VersionMismatch("", 0, 0)
79  {
80  }
81  explicit VersionMismatch(const std::string& text, const uint32_t version_req, const uint32_t version_actual)
82  : std::runtime_error(text)
83  {
84  version_required_ = version_req;
85  version_actual_ = version_actual;
86  std::stringstream ss;
87  ss << text << "(Required version: " << version_required_ << ", actual version: " << version_actual_ << ")";
88  text_ = ss.str();
89  }
90  virtual ~VersionMismatch() = default;
91 
92  virtual const char* what() const noexcept override
93  {
94  return text_.c_str();
95  }
96 
97 private:
99  uint32_t version_actual_;
100  std::string text_;
101 };
102 
107 {
108 public:
110  {
111  }
112  explicit ToolCommNotAvailable(const std::string& text, const uint32_t version_req, const uint32_t version_actual)
113  : std::runtime_error(text), VersionMismatch(text, version_req, version_actual)
114  {
115  }
116 };
117 
122 {
123 public:
124  explicit TimeoutException() = delete;
125  explicit TimeoutException(const std::string& text, std::chrono::milliseconds timeout) : std::runtime_error(text)
126  {
127  std::stringstream ss;
128  ss << text << "(Configured timeout: " << timeout.count() / 1000.0 << " sec)";
129  text_ = ss.str();
130  }
131 
132  explicit TimeoutException(const std::string& text, timeval timeout) : std::runtime_error(text)
133  {
134  std::stringstream ss;
135  ss << text << "(Configured timeout: " << timeout.tv_sec + timeout.tv_usec * 1e-6 << " sec)";
136  text_ = ss.str();
137  }
138  virtual const char* what() const noexcept override
139  {
140  return text_.c_str();
141  }
142 
143 private:
144  std::string text_;
145 };
146 
148 {
149 public:
150  explicit IncompatibleRobotVersion() = delete;
151  explicit IncompatibleRobotVersion(const std::string& text, const VersionInformation& minimum_robot_version,
152  const VersionInformation& actual_robot_version)
153  : std::runtime_error(text)
154  {
155  std::stringstream ss;
156  ss << text << "\n"
157  << "The requested feature is incompatible with the connected robot. Minimum required Polyscope version: "
158  << minimum_robot_version << ", actual Polyscope version: " << actual_robot_version;
159  text_ = ss.str();
160  }
161  virtual const char* what() const noexcept override
162  {
163  return text_.c_str();
164  }
165 
166 private:
167  std::string text_;
168 };
169 
170 class InvalidRange : public UrException
171 {
172 private:
173  std::string text_;
174 
175 public:
176  explicit InvalidRange() = delete;
177  explicit InvalidRange(std::string text) : std::runtime_error(text)
178  {
179  text_ = text;
180  }
181  virtual const char* what() const noexcept override
182  {
183  return text_.c_str();
184  }
185 };
186 
188 {
189 private:
190  std::string text_;
191 
192 public:
193  explicit MissingArgument() = delete;
194  explicit MissingArgument(std::string text, std::string function_name, std::string argument_name, float default_value)
195  : std::runtime_error("")
196  {
197  std::stringstream ss;
198  ss << text << "\nMissing argument when calling function: " << function_name
199  << ". \nArgument missing: " << argument_name
200  << ". \nSet to default value if not important, default value is: " << default_value;
201  text_ = ss.str();
202  }
203  virtual const char* what() const noexcept override
204  {
205  return text_.c_str();
206  }
207 };
208 
210 {
211 public:
212  explicit UnsupportedMotionType() : std::runtime_error("Unsupported motion type")
213  {
214  }
215 };
216 } // namespace urcl
217 #endif // ifndef UR_CLIENT_LIBRARY_EXCEPTIONS_H_INCLUDED
urcl::VersionMismatch::version_required_
uint32_t version_required_
Definition: exceptions.h:98
version_information.h
urcl::UrException::UrException
UrException()
Definition: exceptions.h:56
urcl::UrException::UrException
UrException(const std::string &what_arg)
Definition: exceptions.h:59
urcl::IncompatibleRobotVersion::IncompatibleRobotVersion
IncompatibleRobotVersion()=delete
urcl
Definition: bin_parser.h:36
urcl::VersionMismatch::text_
std::string text_
Definition: exceptions.h:100
urcl::TimeoutException::TimeoutException
TimeoutException(const std::string &text, timeval timeout)
Definition: exceptions.h:132
urcl::IncompatibleRobotVersion::IncompatibleRobotVersion
IncompatibleRobotVersion(const std::string &text, const VersionInformation &minimum_robot_version, const VersionInformation &actual_robot_version)
Definition: exceptions.h:151
urcl::UnsupportedMotionType::UnsupportedMotionType
UnsupportedMotionType()
Definition: exceptions.h:212
urcl::MissingArgument::MissingArgument
MissingArgument()=delete
urcl::UrException
Our base class for exceptions. Specialized exceptions should inherit from those.
Definition: exceptions.h:53
urcl::VersionMismatch::version_actual_
uint32_t version_actual_
Definition: exceptions.h:99
urcl::VersionInformation
Struct containing a robot's version information.
Definition: version_information.h:42
urcl::VersionMismatch::VersionMismatch
VersionMismatch()
Definition: exceptions.h:78
urcl::InvalidRange::InvalidRange
InvalidRange(std::string text)
Definition: exceptions.h:177
urcl::MissingArgument::text_
std::string text_
Definition: exceptions.h:190
urcl::MissingArgument::what
virtual const char * what() const noexcept override
Definition: exceptions.h:203
urcl::IncompatibleRobotVersion::text_
std::string text_
Definition: exceptions.h:167
urcl::ToolCommNotAvailable::ToolCommNotAvailable
ToolCommNotAvailable(const std::string &text, const uint32_t version_req, const uint32_t version_actual)
Definition: exceptions.h:112
urcl::UrException::~UrException
virtual ~UrException()=default
urcl::UnsupportedMotionType
Definition: exceptions.h:209
urcl::UrException::UrException
UrException(const char *what_arg)
Definition: exceptions.h:62
urcl::TimeoutException
A specialized exception representing that communication to the tool is not possible.
Definition: exceptions.h:121
urcl::InvalidRange::what
virtual const char * what() const noexcept override
Definition: exceptions.h:181
urcl::VersionMismatch::~VersionMismatch
virtual ~VersionMismatch()=default
urcl::InvalidRange::InvalidRange
InvalidRange()=delete
urcl::TimeoutException::TimeoutException
TimeoutException(const std::string &text, std::chrono::milliseconds timeout)
Definition: exceptions.h:125
urcl::InvalidRange
Definition: exceptions.h:170
urcl::IncompatibleRobotVersion
Definition: exceptions.h:147
urcl::ToolCommNotAvailable::ToolCommNotAvailable
ToolCommNotAvailable()
Definition: exceptions.h:109
urcl::MissingArgument::MissingArgument
MissingArgument(std::string text, std::string function_name, std::string argument_name, float default_value)
Definition: exceptions.h:194
urcl::ToolCommNotAvailable
A specialized exception representing that communication to the tool is not possible.
Definition: exceptions.h:106
urcl::VersionMismatch::what
virtual const char * what() const noexcept override
Definition: exceptions.h:92
urcl::TimeoutException::TimeoutException
TimeoutException()=delete
urcl::IncompatibleRobotVersion::what
virtual const char * what() const noexcept override
Definition: exceptions.h:161
urcl::VersionMismatch::VersionMismatch
VersionMismatch(const std::string &text, const uint32_t version_req, const uint32_t version_actual)
Definition: exceptions.h:81
urcl::TimeoutException::what
virtual const char * what() const noexcept override
Definition: exceptions.h:138
urcl::InvalidRange::text_
std::string text_
Definition: exceptions.h:173
urcl::MissingArgument
Definition: exceptions.h:187
urcl::TimeoutException::text_
std::string text_
Definition: exceptions.h:144
urcl::VersionMismatch
A specialized exception representing detection of a not supported UR control version.
Definition: exceptions.h:75


ur_client_library
Author(s): Thomas Timm Andersen, Simon Rasmussen, Felix Exner, Lea Steffen, Tristan Schnell
autogenerated on Mon May 26 2025 02:35:58