41#ifndef GENCAM_EXCEPTION_H_
42#define GENCAM_EXCEPTION_H_
52#include <Base/GCCompatibility.h>
56namespace GENICAM_NAMESPACE
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();
97 GENICAM_NAMESPACE::
gcstring m_ExceptionType;
100 unsigned int m_SourceLine;
103 GENICAM_NAMESPACE::
gcstring m_SourceFileName;
106 GENICAM_NAMESPACE::
gcstring m_Description;
111 GENICAM_NAMESPACE::
gcstring m_EntryPoint;
114 GENICAM_NAMESPACE::
gcstring m_ErrorNodeName;
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)
177 ExceptionReporter(
const char* pSourceFileName,
int SourceLine,
const char* pExceptionType)
178 : m_SourceFileName(pSourceFileName)
179 , m_SourceLine(SourceLine)
180 , m_ExceptionType(pExceptionType)
184 E Report(
const char* pFormat, ...)
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());
206 E Report(
const std::string &s)
208 return E(s.c_str(), m_SourceFileName.c_str(), m_SourceLine, m_ExceptionType.c_str());
211 E Report(
const std::stringstream& 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" )
Portable string implementation.
Platform-dependent type definitions.
printf like creation of exceptions
Definition GCException.h:168
int m_SourceLine
The line within the source file where the exception is thrown.
Definition GCException.h:221
GENICAM_NAMESPACE::gcstring m_ExceptionType
the type of the exception in string
Definition GCException.h:224
GENICAM_NAMESPACE::gcstring m_SourceFileName
the path to the source file where the exception is thrown
Definition GCException.h:218
GenICam's exception class.
Definition GCException.h:63
virtual const char * GetDescription() const
Get error description.
GenericException(const char *pDescription, const char *pSourceFileName, unsigned int SourceLine, const char *pExceptionType)
Constructor.
GenericException(const char *pDescription, const char *pSourceFileName, unsigned int SourceLine)
Constructor.
GenericException(const char *pDescription, const char *pSourceFileName, unsigned int SourceLine, const char *pEntryPoint, const char *pErrorNodeName, const char *pExceptionType)
Constructor (GenApi specific)
A string class which is a clone of std::string.
Definition GCString.h:51
#define DECLARE_EXCEPTION(name)
Definition GCException.h:119