GCException.h
Go to the documentation of this file.
00001 //-----------------------------------------------------------------------------
00002 //  (c) 2004 by Basler Vision Technologies
00003 //  Section: Vision Components
00004 //  Project: GenICam
00005 //  Author:  Fritz Dierks
00006 //  $Header$
00007 //
00008 //  01.10.2014 Stemmer, SD
00009 //             prepared for remove of std::exception base class 
00010 //
00011 //  14.03.2005 Stemmer, RS
00012 //             changed minor things like namespace
00013 //             added a AccessException
00014 //             added a TimeoutException
00015 //
00016 //  21.02.2006 Stemmer, SD
00017 //             used _vsnprintf_s function for VS8 and higher (compiler fork)
00018 //
00019 //  License: This file is published under the license of the EMVA GenICam  Standard Group.
00020 //  A text file describing the legal terms is included in  your installation as 'GenICam_license.pdf'.
00021 //  If for some reason you are missing  this file please contact the EMVA or visit the website
00022 //  (http://www.genicam.org) for a full copy.
00023 //
00024 //  THIS SOFTWARE IS PROVIDED BY THE EMVA GENICAM STANDARD GROUP "AS IS"
00025 //  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
00026 //  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00027 //  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE EMVA GENICAM STANDARD  GROUP
00028 //  OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,  SPECIAL,
00029 //  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT  LIMITED TO,
00030 //  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,  DATA, OR PROFITS;
00031 //  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY  THEORY OF LIABILITY,
00032 //  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE)
00033 //  ARISING IN ANY WAY OUT OF THE USE  OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00034 //  POSSIBILITY OF SUCH DAMAGE.
00035 //-----------------------------------------------------------------------------
00042 #ifndef GENCAM_EXCEPTION_H_
00043 #define GENCAM_EXCEPTION_H_
00044 
00045 #include <cassert>
00046 #include <cstdarg>
00047 #include <exception>
00048 #include <sstream>
00049 #include <stdio.h>
00050 #include <stdarg.h>
00051 #include <Base/GCTypes.h>
00052 #include <Base/GCString.h>
00053 
00054 #pragma pack(push, 8)
00055 
00056 namespace GENICAM_NAMESPACE
00057 {
00062     class GCBASE_RTTI_CLASS_API GenericException 
00063     {
00064     public:
00066         GenericException(const char* pDescription, const char *pSourceFileName, unsigned int SourceLine);
00067 
00069         GenericException(const char* pDescription, const char *pSourceFileName, unsigned int SourceLine, const char* pExceptionType);
00070 
00072         GenericException(const char* pDescription, const char *pSourceFileName, unsigned int SourceLine, const char *pEntryPoint, const char *pErrorNodeName, const char* pExceptionType);
00073 
00075         virtual const char* GetDescription() const throw();
00076 
00078         virtual const char* GetSourceFileName() const throw();
00079 
00081         virtual unsigned int GetSourceLine() const throw();
00082 
00084         virtual const char *what() const throw();
00085 
00086         virtual ~GenericException() throw();
00087 
00088     private:
00089 
00091         void AssembleMessage();
00092 
00094         GENICAM_NAMESPACE::gcstring m_What;
00095 
00097         GENICAM_NAMESPACE::gcstring m_ExceptionType;
00098 
00100         unsigned int m_SourceLine;
00101 
00103         GENICAM_NAMESPACE::gcstring m_SourceFileName;
00104 
00106         GENICAM_NAMESPACE::gcstring m_Description;
00107 
00108         /* the following members are GenApi specific */
00109 
00111         GENICAM_NAMESPACE::gcstring m_EntryPoint;
00112 
00114         GENICAM_NAMESPACE::gcstring m_ErrorNodeName;
00115     };
00116 
00119 #define DECLARE_EXCEPTION( name ) \
00120         class GCBASE_RTTI_CLASS_API name : public GENICAM_NAMESPACE::GenericException \
00121             { \
00122         public: \
00123             name( const char* pDescription, const char *pSourceFileName, int SourceLine ); \
00124             name( const char* pDescription, const char *pSourceFileName, int SourceLine, const char* pExceptionType  ); \
00125             name( const char* pDescription, const char *pSourceFileName, int SourceLine, const char *pEntryPoint, const char *pErrorNodeName, const char* pExceptionType ); \
00126             }
00127 
00129     
00130     DECLARE_EXCEPTION(BadAllocException);
00131 
00133     DECLARE_EXCEPTION(InvalidArgumentException);
00134 
00136     DECLARE_EXCEPTION(OutOfRangeException);
00137 
00139     DECLARE_EXCEPTION(PropertyException);
00140 
00142     DECLARE_EXCEPTION(RuntimeException);
00143 
00145     DECLARE_EXCEPTION(LogicalErrorException);
00146 
00148     DECLARE_EXCEPTION(AccessException);
00149 
00151     DECLARE_EXCEPTION(TimeoutException);
00152 
00154     DECLARE_EXCEPTION(DynamicCastException);
00155 
00157 
00158     /*-----------------------------------------------------------------*/
00159     // Utilities
00160     /*-----------------------------------------------------------------*/
00161 
00166     template <typename E>
00167     class ExceptionReporter
00168     {
00169     public:
00170 
00171         ExceptionReporter(const char* pSourceFileName, int SourceLine)
00172             : m_SourceFileName(pSourceFileName)
00173             , m_SourceLine(SourceLine)
00174         {
00175         }
00176 
00177         ExceptionReporter(const char* pSourceFileName, int SourceLine, const char* pExceptionType)
00178             : m_SourceFileName(pSourceFileName)
00179             , m_SourceLine(SourceLine)
00180             , m_ExceptionType(pExceptionType)
00181         {
00182         }
00183 
00184         E Report(const char* pFormat, ...)
00185         {
00186             char pBuffer[256];
00187             va_list vap;
00188             va_start(vap, pFormat);
00189 
00190 #               if defined (_MSC_VER)
00191             vsnprintf_s(pBuffer, sizeof pBuffer, _TRUNCATE, pFormat, vap);
00192 #               else 
00193             vsnprintf( pBuffer, sizeof pBuffer, pFormat, vap );
00194 #               endif 
00195 
00196             va_end(vap);
00197 
00198             return E(pBuffer, m_SourceFileName.c_str(), m_SourceLine, m_ExceptionType.c_str());
00199         };
00200 
00201         E Report()
00202         {
00203             return E("", m_SourceFileName.c_str(), m_SourceLine, m_ExceptionType.c_str());
00204         }
00205 
00206         E Report(const std::string &s)
00207         {
00208             return E(s.c_str(), m_SourceFileName.c_str(), m_SourceLine, m_ExceptionType.c_str());
00209         }
00210 
00211         E Report(const std::stringstream& str)
00212         {
00213             return E(str.str().c_str(), m_SourceFileName.c_str(), m_SourceLine, m_ExceptionType.c_str());
00214         }
00215 
00216     protected:
00218         GENICAM_NAMESPACE::gcstring m_SourceFileName;
00219 
00221         int m_SourceLine;
00222 
00224         GENICAM_NAMESPACE::gcstring m_ExceptionType;
00225     };
00226 
00229 
00231     #define GENERIC_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::GenericException>(__FILE__, __LINE__).Report
00232 
00234     #define BAD_ALLOC_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::BadAllocException>(__FILE__, __LINE__, "BadAllocException" ).Report
00235 
00237     #define INVALID_ARGUMENT_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::InvalidArgumentException>(__FILE__, __LINE__, "InvalidArgumentException" ).Report
00238 
00240     #define OUT_OF_RANGE_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::OutOfRangeException>(__FILE__, __LINE__, "OutOfRangeException" ).Report
00241 
00243     #define PROPERTY_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::PropertyException>(__FILE__, __LINE__, "PropertyException" ).Report
00244 
00246     #define RUNTIME_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::RuntimeException>(__FILE__, __LINE__, "RuntimeException" ).Report
00247 
00249     #define LOGICAL_ERROR_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::LogicalErrorException>(__FILE__,  __LINE__, "LogicalErrorException" ).Report
00250 
00252     #define ACCESS_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::AccessException>(__FILE__, __LINE__, "AccessException" ).Report
00253 
00255     #define TIMEOUT_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::TimeoutException>(__FILE__, __LINE__,"TimeoutException" ).Report
00256 
00258     #define DYNAMICCAST_EXCEPTION GENICAM_NAMESPACE::ExceptionReporter<GENICAM_NAMESPACE::DynamicCastException>(__FILE__, __LINE__, "DynamicCastException" ).Report
00259 
00261     #define CHECK_RANGE_I64(_Value, _Min, _Max, _Inc) \
00262         if((int64_t)(_Value) < (int64_t)(_Min)) \
00263             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)); \
00264                 else if((int64_t)(_Value) > (int64_t)(_Max)) \
00265             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)); \
00266                 else if ( 0 == _Inc ) \
00267             throw LOGICAL_ERROR_EXCEPTION("Increment must not equal 0!"); \
00268                 else if( ((int64_t)(_Value) - (int64_t)(_Min)) % (int64_t)(_Inc) != 0) \
00269             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));
00270 
00272     #define CHECK_RANGE_FLT(_Value, _Min, _Max) \
00273         if ((_Value) < (_Min)) \
00274             throw OUT_OF_RANGE_EXCEPTION( "Value %f must be greater than or equal %f", (_Value), (_Min) ); \
00275         else if ((_Value) > (_Max)) \
00276             throw OUT_OF_RANGE_EXCEPTION( "Value %f must be smaller than or equal %f", (_Value), (_Max) );
00277 
00279     #define CHECK_DYNAMIC_CAST_POINTER( _Pointer )\
00280         assert( (_Pointer) != NULL ); \
00281         if (NULL == (_Pointer)) throw LOGICAL_ERROR_EXCEPTION( "Unexpected type in dynamic cast" )
00282 
00284 
00285 }
00286 
00287 #pragma pack(pop)
00288 
00289 #endif // GENCAM_EXCEPTION_H_


rc_genicam_api
Author(s): Heiko Hirschmueller
autogenerated on Thu Jun 6 2019 18:42:47