00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00042 #ifndef GENCAM_EXCEPTION_H_
00043 #define GENCAM_EXCEPTION_H_
00044
00045 #include <cassert>
00046 #include <cstdarg>
00047 #include <exception>
00048 #include <sstream>
00049 #include <stdio.h>
00050 #include <stdarg.h>
00051 #include <Base/GCTypes.h>
00052 #include <Base/GCString.h>
00053
00054 #pragma pack(push, 8)
00055
00056 namespace GENICAM_NAMESPACE
00057 {
00062 class GCBASE_RTTI_CLASS_API GenericException
00063 {
00064 public:
00066 GenericException(const char* pDescription, const char *pSourceFileName, unsigned int SourceLine);
00067
00069 GenericException(const char* pDescription, const char *pSourceFileName, unsigned int SourceLine, const char* pExceptionType);
00070
00072 GenericException(const char* pDescription, const char *pSourceFileName, unsigned int SourceLine, const char *pEntryPoint, const char *pErrorNodeName, const char* pExceptionType);
00073
00075 virtual const char* GetDescription() const throw();
00076
00078 virtual const char* GetSourceFileName() const throw();
00079
00081 virtual unsigned int GetSourceLine() const throw();
00082
00084 virtual const char *what() const throw();
00085
00086 virtual ~GenericException() throw();
00087
00088 private:
00089
00091 void AssembleMessage();
00092
00094 GENICAM_NAMESPACE::gcstring m_What;
00095
00097 GENICAM_NAMESPACE::gcstring m_ExceptionType;
00098
00100 unsigned int m_SourceLine;
00101
00103 GENICAM_NAMESPACE::gcstring m_SourceFileName;
00104
00106 GENICAM_NAMESPACE::gcstring m_Description;
00107
00108
00109
00111 GENICAM_NAMESPACE::gcstring m_EntryPoint;
00112
00114 GENICAM_NAMESPACE::gcstring m_ErrorNodeName;
00115 };
00116
00119 #define DECLARE_EXCEPTION( name ) \
00120 class GCBASE_RTTI_CLASS_API name : public GENICAM_NAMESPACE::GenericException \
00121 { \
00122 public: \
00123 name( const char* pDescription, const char *pSourceFileName, int SourceLine ); \
00124 name( const char* pDescription, const char *pSourceFileName, int SourceLine, const char* pExceptionType ); \
00125 name( const char* pDescription, const char *pSourceFileName, int SourceLine, const char *pEntryPoint, const char *pErrorNodeName, const char* pExceptionType ); \
00126 }
00127
00129
00130 DECLARE_EXCEPTION(BadAllocException);
00131
00133 DECLARE_EXCEPTION(InvalidArgumentException);
00134
00136 DECLARE_EXCEPTION(OutOfRangeException);
00137
00139 DECLARE_EXCEPTION(PropertyException);
00140
00142 DECLARE_EXCEPTION(RuntimeException);
00143
00145 DECLARE_EXCEPTION(LogicalErrorException);
00146
00148 DECLARE_EXCEPTION(AccessException);
00149
00151 DECLARE_EXCEPTION(TimeoutException);
00152
00154 DECLARE_EXCEPTION(DynamicCastException);
00155
00157
00158
00159
00160
00161
00166 template <typename E>
00167 class ExceptionReporter
00168 {
00169 public:
00170
00171 ExceptionReporter(const char* pSourceFileName, int SourceLine)
00172 : m_SourceFileName(pSourceFileName)
00173 , m_SourceLine(SourceLine)
00174 {
00175 }
00176
00177 ExceptionReporter(const char* pSourceFileName, int SourceLine, const char* pExceptionType)
00178 : m_SourceFileName(pSourceFileName)
00179 , m_SourceLine(SourceLine)
00180 , m_ExceptionType(pExceptionType)
00181 {
00182 }
00183
00184 E Report(const char* pFormat, ...)
00185 {
00186 char pBuffer[256];
00187 va_list vap;
00188 va_start(vap, pFormat);
00189
00190 # if defined (_MSC_VER)
00191 vsnprintf_s(pBuffer, sizeof pBuffer, _TRUNCATE, pFormat, vap);
00192 # else
00193 vsnprintf( pBuffer, sizeof pBuffer, pFormat, vap );
00194 # endif
00195
00196 va_end(vap);
00197
00198 return E(pBuffer, m_SourceFileName.c_str(), m_SourceLine, m_ExceptionType.c_str());
00199 };
00200
00201 E Report()
00202 {
00203 return E("", m_SourceFileName.c_str(), m_SourceLine, m_ExceptionType.c_str());
00204 }
00205
00206 E Report(const std::string &s)
00207 {
00208 return E(s.c_str(), m_SourceFileName.c_str(), m_SourceLine, m_ExceptionType.c_str());
00209 }
00210
00211 E Report(const std::stringstream& str)
00212 {
00213 return E(str.str().c_str(), m_SourceFileName.c_str(), m_SourceLine, m_ExceptionType.c_str());
00214 }
00215
00216 protected:
00218 GENICAM_NAMESPACE::gcstring m_SourceFileName;
00219
00221 int m_SourceLine;
00222
00224 GENICAM_NAMESPACE::gcstring m_ExceptionType;
00225 };
00226
00229
00231 #define GENERIC_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::GenericException>(__FILE__, __LINE__).Report
00232
00234 #define BAD_ALLOC_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::BadAllocException>(__FILE__, __LINE__, "BadAllocException" ).Report
00235
00237 #define INVALID_ARGUMENT_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::InvalidArgumentException>(__FILE__, __LINE__, "InvalidArgumentException" ).Report
00238
00240 #define OUT_OF_RANGE_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::OutOfRangeException>(__FILE__, __LINE__, "OutOfRangeException" ).Report
00241
00243 #define PROPERTY_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::PropertyException>(__FILE__, __LINE__, "PropertyException" ).Report
00244
00246 #define RUNTIME_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::RuntimeException>(__FILE__, __LINE__, "RuntimeException" ).Report
00247
00249 #define LOGICAL_ERROR_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::LogicalErrorException>(__FILE__, __LINE__, "LogicalErrorException" ).Report
00250
00252 #define ACCESS_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::AccessException>(__FILE__, __LINE__, "AccessException" ).Report
00253
00255 #define TIMEOUT_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::TimeoutException>(__FILE__, __LINE__,"TimeoutException" ).Report
00256
00258 #define DYNAMICCAST_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::DynamicCastException>(__FILE__, __LINE__, "DynamicCastException" ).Report
00259
00261 #define CHECK_RANGE_I64(_Value, _Min, _Max, _Inc) \
00262 if((int64_t)(_Value) < (int64_t)(_Min)) \
00263 throw OUT_OF_RANGE_EXCEPTION("Value = %" FMT_I64 "d must be equal or greater than Min = %" FMT_I64 "d", (int64_t)(_Value), (int64_t)(_Min)); \
00264 else if((int64_t)(_Value) > (int64_t)(_Max)) \
00265 throw OUT_OF_RANGE_EXCEPTION("Value = %" FMT_I64 "d must be equal or smaller than Max = %" FMT_I64 "d", (int64_t)(_Value), (int64_t)(_Max)); \
00266 else if ( 0 == _Inc ) \
00267 throw LOGICAL_ERROR_EXCEPTION("Increment must not equal 0!"); \
00268 else if( ((int64_t)(_Value) - (int64_t)(_Min)) % (int64_t)(_Inc) != 0) \
00269 throw OUT_OF_RANGE_EXCEPTION("The difference between Value = %" FMT_I64 "d and Min = %" FMT_I64 "d must be dividable without rest by Inc = %" FMT_I64 "d", (int64_t)(_Value), (int64_t)(_Min), (int64_t)(_Inc));
00270
00272 #define CHECK_RANGE_FLT(_Value, _Min, _Max) \
00273 if ((_Value) < (_Min)) \
00274 throw OUT_OF_RANGE_EXCEPTION( "Value %f must be greater than or equal %f", (_Value), (_Min) ); \
00275 else if ((_Value) > (_Max)) \
00276 throw OUT_OF_RANGE_EXCEPTION( "Value %f must be smaller than or equal %f", (_Value), (_Max) );
00277
00279 #define CHECK_DYNAMIC_CAST_POINTER( _Pointer )\
00280 assert( (_Pointer) != NULL ); \
00281 if (NULL == (_Pointer)) throw LOGICAL_ERROR_EXCEPTION( "Unexpected type in dynamic cast" )
00282
00284
00285 }
00286
00287 #pragma pack(pop)
00288
00289 #endif // GENCAM_EXCEPTION_H_