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 
54 #pragma pack(push, 8)
55 
56 namespace GENICAM_NAMESPACE
57 {
62  class GCBASE_RTTI_CLASS_API GenericException
63  {
64  public:
66  GenericException(const char* pDescription, const char *pSourceFileName, unsigned int SourceLine);
67 
69  GenericException(const char* pDescription, const char *pSourceFileName, unsigned int SourceLine, const char* pExceptionType);
70 
72  GenericException(const char* pDescription, const char *pSourceFileName, unsigned int SourceLine, const char *pEntryPoint, const char *pErrorNodeName, const char* pExceptionType);
73 
75  virtual const char* GetDescription() const throw();
76 
78  virtual const char* GetSourceFileName() const throw();
79 
81  virtual unsigned int GetSourceLine() const throw();
82 
84  virtual const char *what() const throw();
85 
86  virtual ~GenericException() throw();
87 
88  private:
89 
91  void AssembleMessage();
92 
95 
98 
100  unsigned int m_SourceLine;
101 
104 
107 
108  /* the following members are GenApi specific */
109 
112 
115  };
116 
119 #define DECLARE_EXCEPTION( name ) \
120  class GCBASE_RTTI_CLASS_API name : public GENICAM_NAMESPACE::GenericException \
121  { \
122  public: \
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 ); \
126  }
127 
129 
130  DECLARE_EXCEPTION(BadAllocException);
131 
133  DECLARE_EXCEPTION(InvalidArgumentException);
134 
136  DECLARE_EXCEPTION(OutOfRangeException);
137 
139  DECLARE_EXCEPTION(PropertyException);
140 
142  DECLARE_EXCEPTION(RuntimeException);
143 
145  DECLARE_EXCEPTION(LogicalErrorException);
146 
148  DECLARE_EXCEPTION(AccessException);
149 
151  DECLARE_EXCEPTION(TimeoutException);
152 
154  DECLARE_EXCEPTION(DynamicCastException);
155 
157 
158  /*-----------------------------------------------------------------*/
159  // Utilities
160  /*-----------------------------------------------------------------*/
161 
166  template <typename E>
168  {
169  public:
170 
171  ExceptionReporter(const char* pSourceFileName, int SourceLine)
172  : m_SourceFileName(pSourceFileName)
173  , m_SourceLine(SourceLine)
174  {
175  }
176 
177  ExceptionReporter(const char* pSourceFileName, int SourceLine, const char* pExceptionType)
178  : m_SourceFileName(pSourceFileName)
179  , m_SourceLine(SourceLine)
180  , m_ExceptionType(pExceptionType)
181  {
182  }
183 
184  E Report(const char* pFormat, ...)
185  {
186  char pBuffer[256];
187  va_list vap;
188  va_start(vap, pFormat);
189 
190 # if defined (_MSC_VER)
191  vsnprintf_s(pBuffer, sizeof pBuffer, _TRUNCATE, pFormat, vap);
192 # else
193  vsnprintf( pBuffer, sizeof pBuffer, pFormat, vap );
194 # endif
195 
196  va_end(vap);
197 
198  return E(pBuffer, m_SourceFileName.c_str(), m_SourceLine, m_ExceptionType.c_str());
199  };
200 
201  E Report()
202  {
203  return E("", m_SourceFileName.c_str(), m_SourceLine, m_ExceptionType.c_str());
204  }
205 
206  E Report(const std::string &s)
207  {
208  return E(s.c_str(), m_SourceFileName.c_str(), m_SourceLine, m_ExceptionType.c_str());
209  }
210 
211  E Report(const std::stringstream& str)
212  {
213  return E(str.str().c_str(), m_SourceFileName.c_str(), m_SourceLine, m_ExceptionType.c_str());
214  }
215 
216  protected:
219 
222 
225  };
226 
229 
231  #define GENERIC_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::GenericException>(__FILE__, __LINE__).Report
232 
234  #define BAD_ALLOC_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::BadAllocException>(__FILE__, __LINE__, "BadAllocException" ).Report
235 
237  #define INVALID_ARGUMENT_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::InvalidArgumentException>(__FILE__, __LINE__, "InvalidArgumentException" ).Report
238 
240  #define OUT_OF_RANGE_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::OutOfRangeException>(__FILE__, __LINE__, "OutOfRangeException" ).Report
241 
243  #define PROPERTY_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::PropertyException>(__FILE__, __LINE__, "PropertyException" ).Report
244 
246  #define RUNTIME_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::RuntimeException>(__FILE__, __LINE__, "RuntimeException" ).Report
247 
249  #define LOGICAL_ERROR_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::LogicalErrorException>(__FILE__, __LINE__, "LogicalErrorException" ).Report
250 
252  #define ACCESS_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::AccessException>(__FILE__, __LINE__, "AccessException" ).Report
253 
255  #define TIMEOUT_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::TimeoutException>(__FILE__, __LINE__,"TimeoutException" ).Report
256 
258  #define DYNAMICCAST_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::DynamicCastException>(__FILE__, __LINE__, "DynamicCastException" ).Report
259 
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));
270 
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) );
277 
279  #define CHECK_DYNAMIC_CAST_POINTER( _Pointer )\
280  assert( (_Pointer) != NULL ); \
281  if (NULL == (_Pointer)) throw LOGICAL_ERROR_EXCEPTION( "Unexpected type in dynamic cast" )
282 
284 
285 }
286 
287 #pragma pack(pop)
288 
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)
Definition: GCException.h:211
GENICAM_NAMESPACE::gcstring m_ExceptionType
The full error message.
Definition: GCException.h:97
printf like creation of exceptions
Definition: GCException.h:167
GENICAM_NAMESPACE::gcstring m_ExceptionType
the type of the exception in string
Definition: GCException.h:224
GENICAM_NAMESPACE::gcstring m_What
The full error message.
Definition: GCException.h:94
E Report(const std::string &s)
Definition: GCException.h:206
GENICAM_NAMESPACE::gcstring m_Description
Error description.
Definition: GCException.h:106
DECLARE_EXCEPTION(BadAllocException)
GENICAM_NAMESPACE::gcstring m_SourceFileName
the path to the source file where the exception is thrown
Definition: GCException.h:218
ExceptionReporter(const char *pSourceFileName, int SourceLine)
Definition: GCException.h:171
A string class which is a clone of std::string.
Definition: GCString.h:52
E Report(const char *pFormat,...)
Definition: GCException.h:184
ExceptionReporter(const char *pSourceFileName, int SourceLine, const char *pExceptionType)
Definition: GCException.h:177
Portable string implementation.
GENICAM_NAMESPACE::gcstring m_ErrorNodeName
Node where the error occurred (may be empty)
Definition: GCException.h:114
GENICAM_NAMESPACE::gcstring m_SourceFileName
Filename in which the error occurred.
Definition: GCException.h:103
GenICam&#39;s exception class.
Definition: GCException.h:62
GENICAM_NAMESPACE::gcstring m_EntryPoint
Node and method where the call stack entered the node map (may be empty)
Definition: GCException.h:111
unsigned int m_SourceLine
Line number at which the error occurred.
Definition: GCException.h:100
int m_SourceLine
The line within the source file where the exception is thrown.
Definition: GCException.h:221
Platform-dependent type definitions.


rc_genicam_api
Author(s): Heiko Hirschmueller
autogenerated on Thu Jun 6 2019 19:10:54