00001 /* 00002 * Copyright (c) 2007 SCHUNK GmbH & Co. KG 00003 * Copyright (c) 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA) 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 //====================================================================== 00045 //====================================================================== 00046 00047 #ifndef SDHEXCEPTION_H_ 00048 #define SDHEXCEPTION_H_ 00049 00050 //---------------------------------------------------------------------- 00051 // System Includes - include with <> 00052 //---------------------------------------------------------------------- 00053 00054 #include <iostream> 00055 #include <exception> 00056 #include <stdarg.h> 00057 #include <cstdio> // needed in gcc-4.4 (as reported by Hannes Saal) 00058 00059 //---------------------------------------------------------------------- 00060 // Project Includes - include with "" 00061 //---------------------------------------------------------------------- 00062 00063 #include "sdhlibrary_settings.h" 00064 00065 //---------------------------------------------------------------------- 00066 // Defines, enums, unions, structs, 00067 //---------------------------------------------------------------------- 00068 00069 NAMESPACE_SDH_START 00070 00071 00072 //---------------------------------------------------------------------- 00073 // Global variables 00074 //---------------------------------------------------------------------- 00075 00076 00077 //---------------------------------------------------------------------- 00078 // Function and class declaration 00079 //---------------------------------------------------------------------- 00080 00094 class VCC_EXPORT cMsg 00095 { 00096 protected: 00097 00099 enum 00100 { 00101 eMAX_MSG = 512 00102 }; 00103 00104 char msg[ eMAX_MSG ]; 00105 00106 public: 00108 cMsg(); 00109 00110 00112 cMsg(cMsg const & other); 00113 00114 00116 cMsg(char const* fmt, ...) SDH__attribute__((format(printf, 2, 3))); 00117 00118 /* 00119 Remark: 00120 Since non-static C++ methods have an implicit `this' argument, 00121 the arguments of such methods should be counted from two, not 00122 one, when giving values for STRING-INDEX and FIRST-TO-CHECK 00123 parameter of the format __attribute__.) 00124 */ 00125 00126 00128 char const *c_str() const; 00129 00130 }; 00131 00132 VCC_EXPORT std::ostream &operator<<(std::ostream &stream, cMsg const &msg); 00133 00134 00135 //====================================================================== 00136 00150 class VCC_EXPORT cSDHLibraryException: public std::exception 00151 { 00152 00153 protected: 00155 cMsg msg; 00156 00157 public: 00211 cSDHLibraryException(char const * _type, cMsg const & _msg); 00212 00216 virtual const char* what() const throw(); 00217 00218 }; // cSDHLibraryException 00219 //---------------------------------------------------------------------- 00220 00224 class VCC_EXPORT cSDHErrorCommunication: public cSDHLibraryException 00225 { 00226 public: 00227 cSDHErrorCommunication(cMsg const & _msg) 00228 : cSDHLibraryException("cSDHErrorCommunication", _msg) 00229 {} 00230 00231 cSDHErrorCommunication(char const* _type, cMsg const & _msg) 00232 : cSDHLibraryException(_type, _msg) 00233 {} 00234 }; 00235 //----------------------------------------------------------------- 00236 00237 VCC_EXPORT std::ostream &operator<<(std::ostream &stream, cSDHLibraryException const &e); 00238 00239 //====================================================================== 00240 00241 NAMESPACE_SDH_END 00242 00243 #endif 00244 00245 00246 //====================================================================== 00247 /* 00248 Here are some settings for the emacs/xemacs editor (and can be safely ignored): 00249 (e.g. to explicitely set C++ mode for *.h header files) 00250 00251 Local Variables: 00252 mode:C++ 00253 mode:ELSE 00254 End: 00255 */ 00256 //======================================================================