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 // This file is part of the SCHUNK Canopen Driver suite.
5 //
6 // This program is free software licensed under the LGPL
7 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
8 // You can find a copy of this license in LICENSE folder in the top
9 // directory of the source code.
10 //
11 // © Copyright 2016 SCHUNK GmbH, Lauffen/Neckar Germany
12 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
13 // -- END LICENSE BLOCK ------------------------------------------------
14 
15 //----------------------------------------------------------------------
22 //----------------------------------------------------------------------
23 
24 #ifndef ICL_HARDWARE_CANOPEN_EXCEPTIONS_H_INCLUDED
25 #define ICL_HARDWARE_CANOPEN_EXCEPTIONS_H_INCLUDED
26 
27 #include <exception>
28 #include <iostream>
29 #include "helper.h"
30 
31 namespace icl_hardware{
32 namespace canopen_schunk{
33 
37 class ProtocolException : public std::exception
38 {
39 public:
41  const uint8_t subindex,
42  const std::string& error_msg = "none")
43  : index_(index),
44  subindex_(subindex),
45  error_msg_(error_msg)
46  {}
47 
48  virtual ~ProtocolException(void) _GLIBCXX_USE_NOEXCEPT {}
49 
50  virtual const char* what() const _GLIBCXX_USE_NOEXCEPT
51  {
52  std::stringstream ss;
53  ss << "A protocol error occurred at index " << hexToString(index_) << ", subindex " <<
54  hexToString(subindex_) << ". Additional information: " << error_msg_ << std::endl;
55  return ss.str().c_str();
56  }
57 
58 
59 protected:
62  std::string error_msg_;
63 };
64 
69 {
70 public:
72  const uint8_t subindex,
73  const std::string& error_msg = "none")
74  : ProtocolException (index, subindex, error_msg)
75  {}
76 
77  virtual ~ResponseException(void) _GLIBCXX_USE_NOEXCEPT {}
78 
79  virtual const char* what() const _GLIBCXX_USE_NOEXCEPT
80  {
81  std::stringstream ss;
82  ss << "An invalid response was received for request at index " << hexToString(index_) <<
83  ", subindex " << hexToString(subindex_) << ". Additional information: " << error_msg_;
84  return ss.str().c_str();
85  }
86 };
87 
92 {
93 public:
95  const uint8_t subindex,
96  const std::string& error_msg = "none")
97  : ProtocolException (index, subindex, error_msg)
98  {}
99 
100  virtual ~TimeoutException(void) _GLIBCXX_USE_NOEXCEPT {}
101 
102  virtual const char* what() const _GLIBCXX_USE_NOEXCEPT
103  {
104  std::stringstream ss;
105  ss << "Timeout while waiting for response at index " << hexToString(index_) <<
106  ", subindex " << hexToString(subindex_) << ". Additional information: " << error_msg_;
107  return ss.str().c_str();
108  }
109 };
110 
114 class PDOException : public std::exception
115 {
116 public:
117  PDOException(const std::string& error_msg = "none")
118  : m_error_msg (error_msg)
119  {}
120 
121  virtual ~PDOException(void) _GLIBCXX_USE_NOEXCEPT {}
122 
123  virtual const char* what() const _GLIBCXX_USE_NOEXCEPT
124  {
125  return m_error_msg.c_str();
126  }
127 
128 protected:
129  std::string m_error_msg;
130 };
131 
135 class DeviceException : public std::exception
136 {
137 public:
138  DeviceException(const std::string& error_string)
139  : m_error_string(error_string)
140  {}
141 
142  virtual ~DeviceException(void) _GLIBCXX_USE_NOEXCEPT {}
143 
144  virtual const char* what() const _GLIBCXX_USE_NOEXCEPT
145  {
146  std::stringstream ss;
147  ss << m_error_string << " Check your configuration and make sure the device " <<
148  "is properly connected.";
149  return ss.str().c_str();
150  }
151 
152 protected:
153  std::string m_error_string;
154 };
155 
159 class NotFoundException : public std::exception
160 {
161 public:
162  NotFoundException(const std::string& error_string)
163  : m_error_string(error_string)
164  {}
165 
166  virtual ~NotFoundException(void) _GLIBCXX_USE_NOEXCEPT {}
167 
168  virtual const char* what() const _GLIBCXX_USE_NOEXCEPT
169  {
170  return m_error_string.c_str();
171  }
172 
173 protected:
174  std::string m_error_string;
175 };
176 
177 }} // end of NS
178 
179 #endif
virtual ~ResponseException(void) _GLIBCXX_USE_NOEXCEPT
Definition: exceptions.h:77
virtual ~ProtocolException(void) _GLIBCXX_USE_NOEXCEPT
Definition: exceptions.h:48
ResponseException(const uint16_t index, const uint8_t subindex, const std::string &error_msg="none")
Definition: exceptions.h:71
virtual const char * what() const _GLIBCXX_USE_NOEXCEPT
Definition: exceptions.h:102
virtual const char * what() const _GLIBCXX_USE_NOEXCEPT
Definition: exceptions.h:79
TimeoutException(const uint16_t index, const uint8_t subindex, const std::string &error_msg="none")
Definition: exceptions.h:94
virtual const char * what() const _GLIBCXX_USE_NOEXCEPT
Definition: exceptions.h:168
Basic CanOpen exception that contains the Object dictionary index and subindex.
Definition: exceptions.h:37
virtual ~NotFoundException(void) _GLIBCXX_USE_NOEXCEPT
Definition: exceptions.h:166
virtual const char * what() const _GLIBCXX_USE_NOEXCEPT
Definition: exceptions.h:144
If a device response times out, this exception will be thrown.
Definition: exceptions.h:91
PDO related exceptions go here.
Definition: exceptions.h:114
unsigned char uint8_t
This exception is thrown if a requested node or node group does not exist.
Definition: exceptions.h:159
Exceptions relating to device responses.
Definition: exceptions.h:68
virtual ~PDOException(void) _GLIBCXX_USE_NOEXCEPT
Definition: exceptions.h:121
virtual ~DeviceException(void) _GLIBCXX_USE_NOEXCEPT
Definition: exceptions.h:142
DeviceException(const std::string &error_string)
Definition: exceptions.h:138
If something goes wrong with the host&#39;s CAN controller, this exception will be used.
Definition: exceptions.h:135
NotFoundException(const std::string &error_string)
Definition: exceptions.h:162
ProtocolException(const uint16_t index, const uint8_t subindex, const std::string &error_msg="none")
Definition: exceptions.h:40
virtual const char * what() const _GLIBCXX_USE_NOEXCEPT
Definition: exceptions.h:123
PDOException(const std::string &error_msg="none")
Definition: exceptions.h:117
virtual ~TimeoutException(void) _GLIBCXX_USE_NOEXCEPT
Definition: exceptions.h:100
virtual const char * what() const _GLIBCXX_USE_NOEXCEPT
Definition: exceptions.h:50
std::string hexToString(const uint64_t num)
Converts a hexadecimal number into its string representation 0xXX.
Definition: helper.cpp:33
unsigned short uint16_t


schunk_canopen_driver
Author(s): Felix Mauch , Georg Heppner
autogenerated on Mon Jun 10 2019 15:07:49