00001 /*! 00002 * \file SickException.hh 00003 * \brief Contains some simple exception classes. 00004 * 00005 * Code by Jason C. Derenick and Thomas H. Miller. 00006 * Contact derenick(at)lehigh(dot)edu 00007 * 00008 * The Sick LIDAR Matlab/C++ Toolbox 00009 * Copyright (c) 2008, Jason C. Derenick and Thomas H. Miller 00010 * All rights reserved. 00011 * 00012 * This software is released under a BSD Open-Source License. 00013 * See http://sicktoolbox.sourceforge.net 00014 */ 00015 00016 #ifndef SICK_EXCEPTION 00017 #define SICK_EXCEPTION 00018 00019 /* Auto-generated header */ 00020 #include "SickConfig.hh" 00021 00022 /* Definition dependencies */ 00023 #include <string> 00024 #include <exception> 00025 00026 /* Associate the namespace */ 00027 namespace SickToolbox { 00028 00029 /** \class SickException 00030 * \brief Provides a base exception class from 00031 * which to derive other Sick exceptions 00032 */ 00033 class SickException : std::exception { 00034 00035 public: 00036 00037 /** 00038 * \brief A standard constructor 00039 * \param general_str A descriptive "general" string 00040 */ 00041 SickException( const std::string general_str ) : 00042 _general_str(general_str), _detailed_str("") { } 00043 00044 /** 00045 * \brief A standard constructor 00046 * \param general_str A descriptive "general" string 00047 * \param detailed_str A more detailed description 00048 */ 00049 SickException( const std::string general_str, const std::string detailed_str ) : 00050 _general_str(general_str), _detailed_str(detailed_str) { } 00051 00052 /** 00053 * \brief From the standard exception library 00054 */ 00055 virtual const char* what( ) const throw() { 00056 std::string result = _general_str + " " + _detailed_str; 00057 return result.c_str(); 00058 } 00059 00060 /** 00061 * \brief A destructor 00062 */ 00063 ~SickException() throw() {} 00064 00065 private: 00066 00067 /** The string identifier */ 00068 std::string _general_str; 00069 00070 /** For each sub-class to give more details */ 00071 std::string _detailed_str; 00072 00073 }; 00074 00075 /** 00076 * \class SickTimeoutException 00077 * \brief Makes handling timeouts much easier 00078 */ 00079 class SickTimeoutException : public SickException { 00080 00081 public: 00082 00083 /** 00084 * \brief A constructor 00085 */ 00086 SickTimeoutException() : 00087 SickException("A Timeout Occurred!") { } 00088 00089 /** 00090 * \brief A constructor 00091 * \param detailed_str A more detailed description 00092 */ 00093 SickTimeoutException( const std::string detailed_str ) : 00094 SickException("A Timeout Occurred -",detailed_str) { } 00095 00096 /** 00097 * \brief A destructor 00098 */ 00099 ~SickTimeoutException() throw() { } 00100 00101 }; 00102 00103 /** 00104 * \class SickIOException 00105 * \brief Thrown instance where the driver can't 00106 * read,write,drain,flush,... the buffers 00107 */ 00108 class SickIOException : public SickException { 00109 00110 public: 00111 00112 /** 00113 * \brief A constructor 00114 */ 00115 SickIOException() : 00116 SickException("ERROR: I/O exception!") { } 00117 00118 /** 00119 * \brief Another constructor 00120 * \param detailed_str A more detailed description 00121 */ 00122 SickIOException( const std::string detailed_str ) : 00123 SickException("ERROR: I/O exception -",detailed_str) { } 00124 00125 /** 00126 * \brief A destructor 00127 */ 00128 ~SickIOException() throw() { } 00129 00130 }; 00131 00132 /** 00133 * \class SickBadChecksumException 00134 * \brief Thrown when a received message has an 00135 * invalid checksum 00136 */ 00137 class SickBadChecksumException : public SickException { 00138 00139 public: 00140 00141 /** 00142 * \brief A constructor 00143 */ 00144 SickBadChecksumException() : 00145 SickException("ERROR: Bad Checksum!") { } 00146 00147 /** 00148 * \brief Another constructor 00149 * \param detailed_str A more detailed description 00150 */ 00151 SickBadChecksumException( const std::string detailed_str ) : 00152 SickException("ERROR: Bad Checksum -",detailed_str) { } 00153 00154 /** 00155 * \brief A destructor 00156 */ 00157 ~SickBadChecksumException() throw() { } 00158 00159 }; 00160 00161 /** 00162 * \class SickThreadException 00163 * \brief Thrown when error occurs during thread 00164 * initialization, and uninitialization 00165 */ 00166 class SickThreadException : public SickException { 00167 00168 public: 00169 00170 /** 00171 * \brief A constructor 00172 */ 00173 SickThreadException() : 00174 SickException("ERROR: Sick thread exception!") { } 00175 00176 /** 00177 * \brief Another constructor 00178 * \param detailed_str A more detailed description 00179 */ 00180 SickThreadException( const std::string detailed_str ) : 00181 SickException("ERROR: Sick thread exception -",detailed_str) { } 00182 00183 /** 00184 * \brief A destructor 00185 */ 00186 ~SickThreadException() throw() { } 00187 00188 }; 00189 00190 /** 00191 * \class SickConfigException 00192 * \brief Thrown when the driver detects (or the Sick reports) 00193 * an invalid config 00194 */ 00195 class SickConfigException : public SickException { 00196 00197 public: 00198 00199 /** 00200 * \brief A constructor 00201 */ 00202 SickConfigException() : 00203 SickException("ERROR: Config exception!") { } 00204 00205 /** 00206 * \brief Another constructor 00207 * \param detailed_str A more detailed description 00208 */ 00209 SickConfigException( const std::string detailed_str ) : 00210 SickException("ERROR: Config exception -",detailed_str) { } 00211 00212 /** 00213 * \brief A destructor 00214 */ 00215 ~SickConfigException() throw() { } 00216 00217 }; 00218 00219 /** 00220 * \class SickErrorException 00221 * \brief Thrown when Sick returns an error code 00222 * or an unexpected response. 00223 */ 00224 class SickErrorException : public SickException { 00225 00226 public: 00227 00228 /** 00229 * \brief A constructor 00230 */ 00231 SickErrorException() : 00232 SickException("ERROR: Sick returned error code!") { }; 00233 00234 /** 00235 * \brief Another constructor 00236 * \param detailed_str A more detailed description 00237 */ 00238 SickErrorException( const char* detailed_str ) : 00239 SickException("ERROR: Sick error -", detailed_str) { } 00240 00241 /** 00242 * \brief A destructor 00243 */ 00244 ~SickErrorException() throw() { } 00245 00246 }; 00247 } /* namespace SickToolbox */ 00248 00249 #endif /* SICK_EXCEPTION */