GCException.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 // (c) 2004 by Basler Vision Technologies
3 // Section: Vision Components
4 // Project: GenICam
5 // Author: Fritz Dierks
6 // $Header$
7 //
8 // 01.10.2014 Stemmer, SD
9 // prepared for remove of std::exception base class
10 //
11 // 14.03.2005 Stemmer, RS
12 // changed minor things like namespace
13 // added a AccessException
14 // added a TimeoutException
15 //
16 // 21.02.2006 Stemmer, SD
17 // used _vsnprintf_s function for VS8 and higher (compiler fork)
18 //
19 // License: This file is published under the license of the EMVA GenICam Standard Group.
20 // A text file describing the legal terms is included in your installation as 'GenICam_license.pdf'.
21 // If for some reason you are missing this file please contact the EMVA or visit the website
22 // (http://www.genicam.org) for a full copy.
23 //
24 // THIS SOFTWARE IS PROVIDED BY THE EMVA GENICAM STANDARD GROUP "AS IS"
25 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
26 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE EMVA GENICAM STANDARD GROUP
28 // OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
31 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 // POSSIBILITY OF SUCH DAMAGE.
35 //-----------------------------------------------------------------------------
42 #ifndef GENCAM_EXCEPTION_H_
43 #define GENCAM_EXCEPTION_H_
44 
45 #include <cassert>
46 #include <cstdarg>
47 #include <exception>
48 #include <sstream>
49 #include <stdio.h>
50 #include <stdarg.h>
51 #include <Base/GCTypes.h>
52 #include <Base/GCString.h>
53 #include <Base/GCCompatibility.h>
54 
55 #pragma pack(push, 8)
56 
57 namespace GENICAM_NAMESPACE
58 {
63  class GCBASE_RTTI_CLASS_API GenericException
64  {
65  public:
67  GenericException(const char* pDescription, const char *pSourceFileName, unsigned int SourceLine);
68 
70  GenericException(const char* pDescription, const char *pSourceFileName, unsigned int SourceLine, const char* pExceptionType);
71 
73  GenericException(const char* pDescription, const char *pSourceFileName, unsigned int SourceLine, const char *pEntryPoint, const char *pErrorNodeName, const char* pExceptionType);
74 
76  virtual const char* GetDescription() const throw();
77 
79  virtual const char* GetSourceFileName() const throw();
80 
82  virtual unsigned int GetSourceLine() const throw();
83 
85  virtual const char *what() const throw();
86 
87  virtual ~GenericException() throw();
88 
89  private:
90 
92  void AssembleMessage();
93 
96 
99 
101  unsigned int m_SourceLine;
102 
105 
108 
109  /* the following members are GenApi specific */
110 
113 
116  };
117 
120 #define DECLARE_EXCEPTION( name ) \
121  class GCBASE_RTTI_CLASS_API name : public GENICAM_NAMESPACE::GenericException \
122  { \
123  public: \
124  name( const char* pDescription, const char *pSourceFileName, int SourceLine ); \
125  name( const char* pDescription, const char *pSourceFileName, int SourceLine, const char* pExceptionType ); \
126  name( const char* pDescription, const char *pSourceFileName, int SourceLine, const char *pEntryPoint, const char *pErrorNodeName, const char* pExceptionType ); \
127  }
128 
130 
131  DECLARE_EXCEPTION(BadAllocException);
132 
134  DECLARE_EXCEPTION(InvalidArgumentException);
135 
137  DECLARE_EXCEPTION(OutOfRangeException);
138 
140  DECLARE_EXCEPTION(PropertyException);
141 
143  DECLARE_EXCEPTION(RuntimeException);
144 
146  DECLARE_EXCEPTION(LogicalErrorException);
147 
149  DECLARE_EXCEPTION(AccessException);
150 
152  DECLARE_EXCEPTION(TimeoutException);
153 
155  DECLARE_EXCEPTION(DynamicCastException);
156 
158 
159  /*-----------------------------------------------------------------*/
160  // Utilities
161  /*-----------------------------------------------------------------*/
162 
167  template <typename E>
169  {
170  public:
171 
172  ExceptionReporter(const char* pSourceFileName, int SourceLine)
173  : m_SourceFileName(pSourceFileName)
174  , m_SourceLine(SourceLine)
175  {
176  }
177 
178  ExceptionReporter(const char* pSourceFileName, int SourceLine, const char* pExceptionType)
179  : m_SourceFileName(pSourceFileName)
180  , m_SourceLine(SourceLine)
181  , m_ExceptionType(pExceptionType)
182  {
183  }
184 
185  E Report(const char* pFormat, ...)
186  {
187  char pBuffer[256];
188  va_list vap;
189  va_start(vap, pFormat);
190 
191 # if defined (_MSC_VER)
192  vsnprintf_s(pBuffer, sizeof pBuffer, _TRUNCATE, pFormat, vap);
193 # else
194  vsnprintf( pBuffer, sizeof pBuffer, pFormat, vap );
195 # endif
196 
197  va_end(vap);
198 
199  return E(pBuffer, m_SourceFileName.c_str(), m_SourceLine, m_ExceptionType.c_str());
200  };
201 
202  E Report()
203  {
204  return E("", m_SourceFileName.c_str(), m_SourceLine, m_ExceptionType.c_str());
205  }
206 
207  E Report(const std::string &s)
208  {
209  return E(s.c_str(), m_SourceFileName.c_str(), m_SourceLine, m_ExceptionType.c_str());
210  }
211 
212  E Report(const std::stringstream& str)
213  {
214  return E(str.str().c_str(), m_SourceFileName.c_str(), m_SourceLine, m_ExceptionType.c_str());
215  }
216 
217  protected:
220 
223 
226  };
227 
230 
232  #define GENERIC_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::GenericException>(__FILE__, __LINE__).Report
233 
235  #define BAD_ALLOC_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::BadAllocException>(__FILE__, __LINE__, "BadAllocException" ).Report
236 
238  #define INVALID_ARGUMENT_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::InvalidArgumentException>(__FILE__, __LINE__, "InvalidArgumentException" ).Report
239 
241  #define OUT_OF_RANGE_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::OutOfRangeException>(__FILE__, __LINE__, "OutOfRangeException" ).Report
242 
244  #define PROPERTY_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::PropertyException>(__FILE__, __LINE__, "PropertyException" ).Report
245 
247  #define RUNTIME_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::RuntimeException>(__FILE__, __LINE__, "RuntimeException" ).Report
248 
250  #define LOGICAL_ERROR_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::LogicalErrorException>(__FILE__, __LINE__, "LogicalErrorException" ).Report
251 
253  #define ACCESS_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::AccessException>(__FILE__, __LINE__, "AccessException" ).Report
254 
256  #define TIMEOUT_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::TimeoutException>(__FILE__, __LINE__,"TimeoutException" ).Report
257 
259  #define DYNAMICCAST_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::DynamicCastException>(__FILE__, __LINE__, "DynamicCastException" ).Report
260 
262  #define CHECK_RANGE_I64(_Value, _Min, _Max, _Inc) \
263  if((int64_t)(_Value) < (int64_t)(_Min)) \
264  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)); \
265  else if((int64_t)(_Value) > (int64_t)(_Max)) \
266  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)); \
267  else if ( 0 == _Inc ) \
268  throw LOGICAL_ERROR_EXCEPTION("Increment must not equal 0!"); \
269  else if( ((int64_t)(_Value) - (int64_t)(_Min)) % (int64_t)(_Inc) != 0) \
270  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));
271 
273  #define CHECK_RANGE_FLT(_Value, _Min, _Max) \
274  if ((_Value) < (_Min)) \
275  throw OUT_OF_RANGE_EXCEPTION( "Value %f must be greater than or equal %f", (_Value), (_Min) ); \
276  else if ((_Value) > (_Max)) \
277  throw OUT_OF_RANGE_EXCEPTION( "Value %f must be smaller than or equal %f", (_Value), (_Max) );
278 
280  #define CHECK_DYNAMIC_CAST_POINTER( _Pointer )\
281  assert( (_Pointer) != NULL ); \
282  if (NULL == (_Pointer)) throw LOGICAL_ERROR_EXCEPTION( "Unexpected type in dynamic cast" )
283 
285 
286 }
287 
288 #pragma pack(pop)
289 
290 #endif // GENCAM_EXCEPTION_H_
virtual GENICAM_NAMESPACE::gcstring GetDescription() const =0
Get a long description of the node.
E Report(const std::stringstream &str)
Definition: GCException.h:212
GENICAM_NAMESPACE::gcstring m_ExceptionType
The full error message.
Definition: GCException.h:98
printf like creation of exceptions
Definition: GCException.h:168
GENICAM_NAMESPACE::gcstring m_ExceptionType
the type of the exception in string
Definition: GCException.h:225
GENICAM_NAMESPACE::gcstring m_What
The full error message.
Definition: GCException.h:95
E Report(const std::string &s)
Definition: GCException.h:207
GENICAM_NAMESPACE::gcstring m_Description
Error description.
Definition: GCException.h:107
DECLARE_EXCEPTION(BadAllocException)
Project wide definitions for compatibility.
GENICAM_NAMESPACE::gcstring m_SourceFileName
the path to the source file where the exception is thrown
Definition: GCException.h:219
ExceptionReporter(const char *pSourceFileName, int SourceLine)
Definition: GCException.h:172
A string class which is a clone of std::string.
Definition: GCString.h:52
E Report(const char *pFormat,...)
Definition: GCException.h:185
ExceptionReporter(const char *pSourceFileName, int SourceLine, const char *pExceptionType)
Definition: GCException.h:178
Portable string implementation.
GENICAM_NAMESPACE::gcstring m_ErrorNodeName
Node where the error occurred (may be empty)
Definition: GCException.h:115
GENICAM_NAMESPACE::gcstring m_SourceFileName
Filename in which the error occurred.
Definition: GCException.h:104
GenICam&#39;s exception class.
Definition: GCException.h:63
GENICAM_NAMESPACE::gcstring m_EntryPoint
Node and method where the call stack entered the node map (may be empty)
Definition: GCException.h:112
unsigned int m_SourceLine
Line number at which the error occurred.
Definition: GCException.h:101
int m_SourceLine
The line within the source file where the exception is thrown.
Definition: GCException.h:222
Platform-dependent type definitions.


rc_genicam_api
Author(s): Heiko Hirschmueller
autogenerated on Wed Mar 17 2021 02:48:40