exceptions.h
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 
00003 // -- BEGIN LICENSE BLOCK ----------------------------------------------
00004 // This file is part of the SCHUNK Canopen Driver suite.
00005 //
00006 // This program is free software licensed under the LGPL
00007 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
00008 // You can find a copy of this license in LICENSE folder in the top
00009 // directory of the source code.
00010 //
00011 // © Copyright 2016 SCHUNK GmbH, Lauffen/Neckar Germany
00012 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00013 // -- END LICENSE BLOCK ------------------------------------------------
00014 
00015 //----------------------------------------------------------------------
00022 //----------------------------------------------------------------------
00023 
00024 #ifndef ICL_HARDWARE_CANOPEN_EXCEPTIONS_H_INCLUDED
00025 #define ICL_HARDWARE_CANOPEN_EXCEPTIONS_H_INCLUDED
00026 
00027 #include <exception>
00028 #include <iostream>
00029 #include "helper.h"
00030 
00031 namespace icl_hardware{
00032 namespace canopen_schunk{
00033 
00037 class ProtocolException : public std::exception
00038 {
00039 public:
00040   ProtocolException(const uint16_t index,
00041                     const uint8_t subindex,
00042                     const std::string& error_msg = "none")
00043     : index_(index),
00044       subindex_(subindex),
00045       error_msg_(error_msg)
00046   {}
00047 
00048   virtual ~ProtocolException(void) _GLIBCXX_USE_NOEXCEPT {}
00049 
00050   virtual const char* what() const _GLIBCXX_USE_NOEXCEPT
00051   {
00052     std::stringstream ss;
00053     ss << "A protocol error occurred at index " << hexToString(index_) << ", subindex " <<
00054     hexToString(subindex_) << ". Additional information: " << error_msg_ << std::endl;
00055     return ss.str().c_str();
00056   }
00057 
00058 
00059 protected:
00060   uint16_t index_;
00061   uint8_t subindex_;
00062   std::string error_msg_;
00063 };
00064 
00068 class ResponseException : public ProtocolException
00069 {
00070 public:
00071   ResponseException(const uint16_t index,
00072                     const uint8_t subindex,
00073                     const std::string& error_msg = "none")
00074     : ProtocolException (index, subindex, error_msg)
00075   {}
00076 
00077   virtual ~ResponseException(void) _GLIBCXX_USE_NOEXCEPT {}
00078 
00079   virtual const char* what() const _GLIBCXX_USE_NOEXCEPT
00080   {
00081     std::stringstream ss;
00082     ss << "An invalid response was received for request at index " << hexToString(index_) <<
00083     ", subindex " << hexToString(subindex_) << ". Additional information: " << error_msg_;
00084     return ss.str().c_str();
00085   }
00086 };
00087 
00091 class TimeoutException : public ProtocolException
00092 {
00093 public:
00094   TimeoutException(const uint16_t index,
00095                     const uint8_t subindex,
00096                     const std::string& error_msg = "none")
00097     : ProtocolException (index, subindex, error_msg)
00098   {}
00099 
00100   virtual ~TimeoutException(void) _GLIBCXX_USE_NOEXCEPT {}
00101 
00102   virtual const char* what() const _GLIBCXX_USE_NOEXCEPT
00103   {
00104     std::stringstream ss;
00105     ss << "Timeout while waiting for response at index  " << hexToString(index_) <<
00106     ", subindex " << hexToString(subindex_) << ". Additional information: " << error_msg_;
00107     return ss.str().c_str();
00108   }
00109 };
00110 
00114 class PDOException : public std::exception
00115 {
00116 public:
00117   PDOException(const std::string& error_msg = "none")
00118     : m_error_msg (error_msg)
00119   {}
00120 
00121   virtual ~PDOException(void) _GLIBCXX_USE_NOEXCEPT {}
00122 
00123   virtual const char* what() const _GLIBCXX_USE_NOEXCEPT
00124   {
00125     return m_error_msg.c_str();
00126   }
00127 
00128 protected:
00129   std::string m_error_msg;
00130 };
00131 
00135 class DeviceException : public std::exception
00136 {
00137 public:
00138   DeviceException(const std::string& error_string)
00139     : m_error_string(error_string)
00140   {}
00141 
00142   virtual ~DeviceException(void) _GLIBCXX_USE_NOEXCEPT {}
00143 
00144   virtual const char* what() const _GLIBCXX_USE_NOEXCEPT
00145   {
00146     std::stringstream ss;
00147     ss << m_error_string << " Check your configuration and make sure the device " <<
00148                     "is properly connected.";
00149     return ss.str().c_str();
00150   }
00151 
00152 protected:
00153   std::string m_error_string;
00154 };
00155 
00159 class NotFoundException : public std::exception
00160 {
00161 public:
00162   NotFoundException(const std::string& error_string)
00163     : m_error_string(error_string)
00164   {}
00165 
00166     virtual ~NotFoundException(void) _GLIBCXX_USE_NOEXCEPT {}
00167 
00168   virtual const char* what() const _GLIBCXX_USE_NOEXCEPT
00169   {
00170     return m_error_string.c_str();
00171   }
00172 
00173 protected:
00174   std::string m_error_string;
00175 };
00176 
00177 }} // end of NS
00178 
00179 #endif


schunk_canopen_driver
Author(s): Felix Mauch , Georg Heppner
autogenerated on Thu Jun 6 2019 20:17:24