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 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
9 //
10 // http://www.apache.org/licenses/LICENSE-2.0
11 //
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
17 // -- END LICENSE BLOCK ------------------------------------------------
18 
19 //----------------------------------------------------------------------
26 //----------------------------------------------------------------------
27 
28 #ifndef UR_CLIENT_LIBRARY_EXCEPTIONS_H_INCLUDED
29 #define UR_CLIENT_LIBRARY_EXCEPTIONS_H_INCLUDED
30 
31 #include <chrono>
32 #include <stdexcept>
33 #include <sstream>
34 
35 namespace urcl
36 {
40 class UrException : virtual public std::runtime_error
41 {
42 public:
43  explicit UrException() : std::runtime_error("")
44  {
45  }
46  explicit UrException(const std::string& what_arg) : std::runtime_error(what_arg)
47  {
48  }
49  explicit UrException(const char* what_arg) : std::runtime_error(what_arg)
50  {
51  }
52 
53  virtual ~UrException() = default;
54 
55 private:
56  /* data */
57 };
58 
63 {
64 public:
65  explicit VersionMismatch() : VersionMismatch("", 0, 0)
66  {
67  }
68  explicit VersionMismatch(const std::string& text, const uint32_t version_req, const uint32_t version_actual)
69  : std::runtime_error(text)
70  {
71  version_required_ = version_req;
72  version_actual_ = version_actual;
73  std::stringstream ss;
74  ss << text << "(Required version: " << version_required_ << ", actual version: " << version_actual_ << ")";
75  text_ = ss.str();
76  }
77  virtual ~VersionMismatch() = default;
78 
79  virtual const char* what() const noexcept override
80  {
81  return text_.c_str();
82  }
83 
84 private:
86  uint32_t version_actual_;
87  std::string text_;
88 };
89 
94 {
95 public:
97  {
98  }
99  explicit ToolCommNotAvailable(const std::string& text, const uint32_t version_req, const uint32_t version_actual)
100  : std::runtime_error(text), VersionMismatch(text, version_req, version_actual)
101  {
102  }
103 };
104 
109 {
110 public:
111  explicit TimeoutException() = delete;
112  explicit TimeoutException(const std::string& text, timeval timeout) : std::runtime_error(text)
113  {
114  std::stringstream ss;
115  ss << text << "(Configured timeout: " << timeout.tv_sec + timeout.tv_usec * 1e-6 << " sec)";
116  text_ = ss.str();
117  }
118  virtual const char* what() const noexcept override
119  {
120  return text_.c_str();
121  }
122 
123 private:
124  std::string text_;
125 };
126 } // namespace urcl
127 #endif // ifndef UR_CLIENT_LIBRARY_EXCEPTIONS_H_INCLUDED
virtual const char * what() const noexceptoverride
Definition: exceptions.h:79
UrException(const char *what_arg)
Definition: exceptions.h:49
TimeoutException(const std::string &text, timeval timeout)
Definition: exceptions.h:112
uint32_t version_required_
Definition: exceptions.h:85
A specialized exception representing detection of a not supported UR control version.
Definition: exceptions.h:62
virtual const char * what() const noexceptoverride
Definition: exceptions.h:118
std::string text_
Definition: exceptions.h:87
A specialized exception representing that communication to the tool is not possible.
Definition: exceptions.h:93
uint32_t version_actual_
Definition: exceptions.h:86
virtual ~UrException()=default
UrException(const std::string &what_arg)
Definition: exceptions.h:46
A specialized exception representing that communication to the tool is not possible.
Definition: exceptions.h:108
VersionMismatch(const std::string &text, const uint32_t version_req, const uint32_t version_actual)
Definition: exceptions.h:68
ToolCommNotAvailable(const std::string &text, const uint32_t version_req, const uint32_t version_actual)
Definition: exceptions.h:99
Our base class for exceptions. Specialized exceptions should inherit from those.
Definition: exceptions.h:40


ur_client_library
Author(s): Thomas Timm Andersen, Simon Rasmussen, Felix Exner, Lea Steffen, Tristan Schnell
autogenerated on Sun May 9 2021 02:16:26