Exception.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 // (c) 2006-11 by Basler Vision Technologies
3 // Section: Vision Components
4 // Project: GenApi
5 // Author: Fritz Dierks
6 // $Header$
7 //
8 // License: This file is published under the license of the EMVA GenICam Standard Group.
9 // A text file describing the legal terms is included in your installation as 'GenICam_license.pdf'.
10 // If for some reason you are missing this file please contact the EMVA or visit the website
11 // (http://www.genicam.org) for a full copy.
12 //
13 // THIS SOFTWARE IS PROVIDED BY THE EMVA GENICAM STANDARD GROUP "AS IS"
14 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE EMVA GENICAM STANDARD GROUP
17 // OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23 // POSSIBILITY OF SUCH DAMAGE.
24 //-----------------------------------------------------------------------------
30 #ifndef GENAPI_EXCEPTION_H
31 #define GENAPI_EXCEPTION_H
32 
33 #include "Base/GCException.h"
34 #include "INodePrivate.h"
35 
36 namespace GENAPI_NAMESPACE
37 {
38 
40  typedef enum
41  {
59  } EMethod;
60 
62  {
63  public:
65  static void ToString(GENICAM_NAMESPACE::gcstring &ValueStr, EMethod *pValue)
66  {
67  assert( pValue );
68 
69  if( *pValue == meGetAccessMode )
70  ValueStr = "GetAccessMode";
71  else if( *pValue == meToString )
72  ValueStr = "ToString";
73  else if( *pValue == meFromString )
74  ValueStr = "FromString";
75  else if( *pValue == meGetValue )
76  ValueStr = "GetValue";
77  else if( *pValue == meSetValue )
78  ValueStr = "SetValue";
79  else if( *pValue == meGetMin )
80  ValueStr = "GetMin";
81  else if( *pValue == meGetMax )
82  ValueStr = "GetMax";
83  else if( *pValue == meGetInc )
84  ValueStr = "GetInc";
85  else if( *pValue == meExecute )
86  ValueStr = "Execute";
87  else if( *pValue == meIsDone )
88  ValueStr = "IsDone";
89  else if( *pValue == meSetIntValue )
90  ValueStr = "SetIntValue";
91  else if( *pValue == meGetIntValue )
92  ValueStr = "GetIntValue";
93  else if( *pValue == meSet )
94  ValueStr = "Set";
95  else if( *pValue == meGet )
96  ValueStr = "Get";
97  else
98  ValueStr = "_UndefinedMethod";
99  }
100 
102  static GENICAM_NAMESPACE::gcstring ToString(EMethod Value)
103  {
105  ToString(Result, &Value);
106  return Result;
107  }
108  };
109 
111 
112  template <class E>
114  {
115  public:
116  ExceptionReporterNode( const char* sourceFileName, unsigned int sourceLine, const INodePrivate* pNodePrivate, const char* pExceptionType )
117  : GENICAM_NAMESPACE::ExceptionReporter<E>( sourceFileName, sourceLine )
118  , m_pNodePrivate( pNodePrivate )
119  , m_ExceptionType( pExceptionType )
120  { }
121 
122  E Report( const char* pFormat, ... )
123  {
124  using namespace GENICAM_NAMESPACE;
125  // print the actual error description to pBuffer
126  char pBuffer[ 256 ];
127  va_list vap;
128  va_start( vap, pFormat );
129 
130 #if defined (_MSC_VER)
131  vsnprintf_s( pBuffer, sizeof pBuffer, _TRUNCATE, pFormat, vap );
132 #else
133  vsnprintf( pBuffer, sizeof pBuffer, pFormat, vap );
134 #endif
135  va_end(vap);
136  return E( pBuffer,
138  getEntryPoint(m_pNodePrivate->GetNodeMap()).c_str(),
139  m_pNodePrivate->GetName().c_str(),
140  m_ExceptionType.c_str()
141  );
142  }
143 
144  private:
145  // The current node
147 
150 
151  };
152 
154 # define GENERIC_EXCEPTION_NODE GENAPI_NAMESPACE::ExceptionReporterNode<GENICAM_NAMESPACE::GenericException>(__FILE__, __LINE__, this, "GenericException" ).Report
155 
157 # define INVALID_ARGUMENT_EXCEPTION_NODE GENAPI_NAMESPACE::ExceptionReporterNode<GENICAM_NAMESPACE::InvalidArgumentException>(__FILE__, __LINE__, this, "InvalidArgumentException" ).Report
158 
160 # define OUT_OF_RANGE_EXCEPTION_NODE GENAPI_NAMESPACE::ExceptionReporterNode<GENICAM_NAMESPACE::OutOfRangeException>(__FILE__, __LINE__, this, "OutOfRangeException" ).Report
161 
163 # define PROPERTY_EXCEPTION_NODE GENAPI_NAMESPACE::ExceptionReporterNode<GENICAM_NAMESPACE::PropertyException>(__FILE__, __LINE__, this, "PropertyException" ).Report
164 
166 # define RUNTIME_EXCEPTION_NODE GENAPI_NAMESPACE::ExceptionReporterNode<GENICAM_NAMESPACE::RuntimeException>(__FILE__, __LINE__, this, "RuntimeException" ).Report
167 
169 # define LOGICAL_ERROR_EXCEPTION_NODE GENAPI_NAMESPACE::ExceptionReporterNode<GENICAM_NAMESPACE::LogicalErrorException>(__FILE__, __LINE__, this, "LogicalErrorException" ).Report
170 
172 # define ACCESS_EXCEPTION_NODE GENAPI_NAMESPACE::ExceptionReporterNode<GENICAM_NAMESPACE::AccessException>(__FILE__, __LINE__, this, "AccessException" ).Report
173 
175 # define TIMEOUT_EXCEPTION_NODE GENAPI_NAMESPACE::ExceptionReporterNode<GENICAM_NAMESPACE::TimeoutException>(__FILE__, __LINE__, this, "TimeoutException" ).Report
176 
178 # define DYNAMICCAST_EXCEPTION_NODE GENAPI_NAMESPACE::ExceptionReporterNode<GENICAM_NAMESPACE::DynamicCastException>(__FILE__, __LINE__, this, "DynamicCastException" ).Report
179 
181 # define CHECK_RANGE_I64_NODE(_Value, _Min, _Max, _Inc) \
182  if((int64_t)(_Value) < (int64_t)(_Min)) \
183  throw OUT_OF_RANGE_EXCEPTION_NODE("Value = %" FMT_I64 "d must be equal or greater than Min = %" FMT_I64 "d.", (int64_t)(_Value), (int64_t)(_Min)); \
184  else if((int64_t)(_Value) > (int64_t)(_Max)) \
185  throw OUT_OF_RANGE_EXCEPTION_NODE("Value = %" FMT_I64 "d must be equal or smaller than Max = %" FMT_I64 "d.", (int64_t)(_Value), (int64_t)(_Max)); \
186  else if ( 0 >= _Inc ) \
187  throw LOGICAL_ERROR_EXCEPTION_NODE("Increment must be larger than 0."); \
188  else if( ((int64_t)(_Value) - (int64_t)(_Min)) % (int64_t)(_Inc) != 0) \
189  throw OUT_OF_RANGE_EXCEPTION_NODE("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));
190 
192 # define CHECK_RANGE_FLT_NODE(_Value, _Min, _Max) \
193  if ((_Value) < (_Min)) \
194  throw OUT_OF_RANGE_EXCEPTION_NODE( "Value %f must be greater than or equal %f.", (_Value), (_Min) ); \
195  else if ((_Value) > (_Max)) \
196  throw OUT_OF_RANGE_EXCEPTION_NODE( "Value %f must be smaller than or equal %f.", (_Value), (_Max) );
197 
198 
199 }
200 
201 #endif // GENAPI_EXCEPTION_H
202 
printf like creation of exceptions
Definition: GCException.h:168
GENICAM_INTERFACE INodePrivate
Interface including the methods for node construction common to all nodes.
Definition: INodePrivate.h:54
GENICAM_INTERFACE INodeMap
Interface to access the node map.
Definition: INode.h:52
GENICAM_NAMESPACE::gcstring m_ExceptionType
The full error message.
Definition: Exception.h:149
ExceptionReporterNode(const char *sourceFileName, unsigned int sourceLine, const INodePrivate *pNodePrivate, const char *pExceptionType)
Definition: Exception.h:116
GENICAM_NAMESPACE::gcstring getEntryPoint(INodeMap *nodeMap)
static GENICAM_NAMESPACE::gcstring ToString(EMethod Value)
Converts a string to an int32_t property.
Definition: Exception.h:102
const INodePrivate * m_pNodePrivate
Definition: Exception.h:146
EMethod
denotes through which method call the node tree was entered
Definition: Exception.h:40
A string class which is a clone of std::string.
Definition: GCString.h:52
static void ToString(GENICAM_NAMESPACE::gcstring &ValueStr, EMethod *pValue)
Converts a string to an int32_t property.
Definition: Exception.h:65
virtual const char * c_str(void) const
E Report(const char *pFormat,...)
Definition: Exception.h:122
Lexical analyzer for CIntSwissKnife.
Definition: Autovector.h:48
Definition of interface INodePrivate.


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