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 
36 namespace urcl
37 {
41 class UrException : virtual public std::runtime_error
42 {
43 public:
44  explicit UrException() : std::runtime_error("")
45  {
46  }
47  explicit UrException(const std::string& what_arg) : std::runtime_error(what_arg)
48  {
49  }
50  explicit UrException(const char* what_arg) : std::runtime_error(what_arg)
51  {
52  }
53 
54  virtual ~UrException() = default;
55 
56 private:
57  /* data */
58 };
59 
64 {
65 public:
66  explicit VersionMismatch() : VersionMismatch("", 0, 0)
67  {
68  }
69  explicit VersionMismatch(const std::string& text, const uint32_t version_req, const uint32_t version_actual)
70  : std::runtime_error(text)
71  {
72  version_required_ = version_req;
73  version_actual_ = version_actual;
74  std::stringstream ss;
75  ss << text << "(Required version: " << version_required_ << ", actual version: " << version_actual_ << ")";
76  text_ = ss.str();
77  }
78  virtual ~VersionMismatch() = default;
79 
80  virtual const char* what() const noexcept override
81  {
82  return text_.c_str();
83  }
84 
85 private:
87  uint32_t version_actual_;
88  std::string text_;
89 };
90 
95 {
96 public:
98  {
99  }
100  explicit ToolCommNotAvailable(const std::string& text, const uint32_t version_req, const uint32_t version_actual)
101  : std::runtime_error(text), VersionMismatch(text, version_req, version_actual)
102  {
103  }
104 };
105 
110 {
111 public:
112  explicit TimeoutException() = delete;
113  explicit TimeoutException(const std::string& text, timeval timeout) : std::runtime_error(text)
114  {
115  std::stringstream ss;
116  ss << text << "(Configured timeout: " << timeout.tv_sec + timeout.tv_usec * 1e-6 << " sec)";
117  text_ = ss.str();
118  }
119  virtual const char* what() const noexcept override
120  {
121  return text_.c_str();
122  }
123 
124 private:
125  std::string text_;
126 };
127 } // namespace urcl
128 #endif // ifndef UR_CLIENT_LIBRARY_EXCEPTIONS_H_INCLUDED
virtual const char * what() const noexcept override
Definition: exceptions.h:119
UrException(const char *what_arg)
Definition: exceptions.h:50
TimeoutException(const std::string &text, timeval timeout)
Definition: exceptions.h:113
uint32_t version_required_
Definition: exceptions.h:86
A specialized exception representing detection of a not supported UR control version.
Definition: exceptions.h:63
std::string text_
Definition: exceptions.h:88
A specialized exception representing that communication to the tool is not possible.
Definition: exceptions.h:94
uint32_t version_actual_
Definition: exceptions.h:87
virtual ~UrException()=default
UrException(const std::string &what_arg)
Definition: exceptions.h:47
A specialized exception representing that communication to the tool is not possible.
Definition: exceptions.h:109
VersionMismatch(const std::string &text, const uint32_t version_req, const uint32_t version_actual)
Definition: exceptions.h:69
ToolCommNotAvailable(const std::string &text, const uint32_t version_req, const uint32_t version_actual)
Definition: exceptions.h:100
virtual const char * what() const noexcept override
Definition: exceptions.h:80
Our base class for exceptions. Specialized exceptions should inherit from those.
Definition: exceptions.h:41


ur_client_library
Author(s): Thomas Timm Andersen, Simon Rasmussen, Felix Exner, Lea Steffen, Tristan Schnell
autogenerated on Tue Jul 4 2023 02:09:47