42 #ifndef GENCAM_EXCEPTION_H_ 43 #define GENCAM_EXCEPTION_H_ 66 GenericException(
const char* pDescription,
const char *pSourceFileName,
unsigned int SourceLine);
69 GenericException(
const char* pDescription,
const char *pSourceFileName,
unsigned int SourceLine,
const char* pExceptionType);
72 GenericException(
const char* pDescription,
const char *pSourceFileName,
unsigned int SourceLine,
const char *pEntryPoint,
const char *pErrorNodeName,
const char* pExceptionType);
78 virtual const char* GetSourceFileName()
const throw();
81 virtual unsigned int GetSourceLine()
const throw();
84 virtual const char *what()
const throw();
91 void AssembleMessage();
119 #define DECLARE_EXCEPTION( name ) \ 120 class GCBASE_RTTI_CLASS_API name : public GENICAM_NAMESPACE::GenericException \ 123 name( const char* pDescription, const char *pSourceFileName, int SourceLine ); \ 124 name( const char* pDescription, const char *pSourceFileName, int SourceLine, const char* pExceptionType ); \ 125 name( const char* pDescription, const char *pSourceFileName, int SourceLine, const char *pEntryPoint, const char *pErrorNodeName, const char* pExceptionType ); \ 166 template <
typename E>
172 : m_SourceFileName(pSourceFileName)
173 , m_SourceLine(SourceLine)
178 : m_SourceFileName(pSourceFileName)
179 , m_SourceLine(SourceLine)
180 , m_ExceptionType(pExceptionType)
188 va_start(vap, pFormat);
190 # if defined (_MSC_VER) 191 vsnprintf_s(pBuffer,
sizeof pBuffer, _TRUNCATE, pFormat, vap);
193 vsnprintf( pBuffer,
sizeof pBuffer, pFormat, vap );
198 return E(pBuffer, m_SourceFileName.c_str(), m_SourceLine, m_ExceptionType.c_str());
203 return E(
"", m_SourceFileName.c_str(), m_SourceLine, m_ExceptionType.c_str());
208 return E(s.c_str(), m_SourceFileName.c_str(), m_SourceLine, m_ExceptionType.c_str());
213 return E(str.str().c_str(), m_SourceFileName.c_str(), m_SourceLine, m_ExceptionType.c_str());
231 #define GENERIC_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::GenericException>(__FILE__, __LINE__).Report 234 #define BAD_ALLOC_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::BadAllocException>(__FILE__, __LINE__, "BadAllocException" ).Report 237 #define INVALID_ARGUMENT_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::InvalidArgumentException>(__FILE__, __LINE__, "InvalidArgumentException" ).Report 240 #define OUT_OF_RANGE_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::OutOfRangeException>(__FILE__, __LINE__, "OutOfRangeException" ).Report 243 #define PROPERTY_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::PropertyException>(__FILE__, __LINE__, "PropertyException" ).Report 246 #define RUNTIME_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::RuntimeException>(__FILE__, __LINE__, "RuntimeException" ).Report 249 #define LOGICAL_ERROR_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::LogicalErrorException>(__FILE__, __LINE__, "LogicalErrorException" ).Report 252 #define ACCESS_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::AccessException>(__FILE__, __LINE__, "AccessException" ).Report 255 #define TIMEOUT_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::TimeoutException>(__FILE__, __LINE__,"TimeoutException" ).Report 258 #define DYNAMICCAST_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::DynamicCastException>(__FILE__, __LINE__, "DynamicCastException" ).Report 261 #define CHECK_RANGE_I64(_Value, _Min, _Max, _Inc) \ 262 if((int64_t)(_Value) < (int64_t)(_Min)) \ 263 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)); \ 264 else if((int64_t)(_Value) > (int64_t)(_Max)) \ 265 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)); \ 266 else if ( 0 == _Inc ) \ 267 throw LOGICAL_ERROR_EXCEPTION("Increment must not equal 0!"); \ 268 else if( ((int64_t)(_Value) - (int64_t)(_Min)) % (int64_t)(_Inc) != 0) \ 269 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)); 272 #define CHECK_RANGE_FLT(_Value, _Min, _Max) \ 273 if ((_Value) < (_Min)) \ 274 throw OUT_OF_RANGE_EXCEPTION( "Value %f must be greater than or equal %f", (_Value), (_Min) ); \ 275 else if ((_Value) > (_Max)) \ 276 throw OUT_OF_RANGE_EXCEPTION( "Value %f must be smaller than or equal %f", (_Value), (_Max) ); 279 #define CHECK_DYNAMIC_CAST_POINTER( _Pointer )\ 280 assert( (_Pointer) != NULL ); \ 281 if (NULL == (_Pointer)) throw LOGICAL_ERROR_EXCEPTION( "Unexpected type in dynamic cast" ) 289 #endif // GENCAM_EXCEPTION_H_ virtual GENICAM_NAMESPACE::gcstring GetDescription() const =0
Get a long description of the node.
E Report(const std::stringstream &str)
GENICAM_NAMESPACE::gcstring m_ExceptionType
The full error message.
printf like creation of exceptions
GENICAM_NAMESPACE::gcstring m_ExceptionType
the type of the exception in string
GENICAM_NAMESPACE::gcstring m_What
The full error message.
E Report(const std::string &s)
GENICAM_NAMESPACE::gcstring m_Description
Error description.
DECLARE_EXCEPTION(BadAllocException)
GENICAM_NAMESPACE::gcstring m_SourceFileName
the path to the source file where the exception is thrown
ExceptionReporter(const char *pSourceFileName, int SourceLine)
A string class which is a clone of std::string.
E Report(const char *pFormat,...)
ExceptionReporter(const char *pSourceFileName, int SourceLine, const char *pExceptionType)
Portable string implementation.
GENICAM_NAMESPACE::gcstring m_ErrorNodeName
Node where the error occurred (may be empty)
GENICAM_NAMESPACE::gcstring m_SourceFileName
Filename in which the error occurred.
GenICam's exception class.
GENICAM_NAMESPACE::gcstring m_EntryPoint
Node and method where the call stack entered the node map (may be empty)
unsigned int m_SourceLine
Line number at which the error occurred.
int m_SourceLine
The line within the source file where the exception is thrown.
Platform-dependent type definitions.