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         gcstring m_What;
00095 
00097         gcstring m_ExceptionType;
00098 
00100         unsigned int m_SourceLine;
00101 
00103         gcstring m_SourceFileName;
00104 
00106         gcstring m_Description;
00107 
00108         /* the following members are GenApi specific */
00109 
00111         gcstring m_EntryPoint;
00112 
00114         gcstring m_ErrorNodeName;
00115     };
00116 
00119 #define DECLARE_EXCEPTION( name ) \
00120         class GCBASE_RTTI_CLASS_API name : public GenICam::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 
00197             return E(pBuffer, m_SourceFileName.c_str(), m_SourceLine, m_ExceptionType.c_str());
00198         };
00199 
00200         E Report()
00201         {
00202             return E("", m_SourceFileName.c_str(), m_SourceLine, m_ExceptionType.c_str());
00203         }
00204 
00205         E Report(const std::string &s)
00206         {
00207             return E(s.c_str(), m_SourceFileName.c_str(), m_SourceLine, m_ExceptionType.c_str());
00208         }
00209 
00210         E Report(const std::stringstream& str)
00211         {
00212             return E(str.str().c_str(), m_SourceFileName.c_str(), m_SourceLine, m_ExceptionType.c_str());
00213         }
00214 
00215     protected:
00217         gcstring m_SourceFileName;
00218 
00220         int m_SourceLine;
00221 
00223         gcstring m_ExceptionType;
00224     };
00225 
00228 
00230     #define GENERIC_EXCEPTION GenICam::ExceptionReporter<GenICam::GenericException>(__FILE__, __LINE__).Report
00231 
00233     #define BAD_ALLOC_EXCEPTION GenICam::ExceptionReporter<GenICam::BadAllocException>(__FILE__, __LINE__, "BadAllocException" ).Report
00234 
00236     #define INVALID_ARGUMENT_EXCEPTION GenICam::ExceptionReporter<GenICam::InvalidArgumentException>(__FILE__, __LINE__, "InvalidArgumentException" ).Report
00237 
00239     #define OUT_OF_RANGE_EXCEPTION GenICam::ExceptionReporter<GenICam::OutOfRangeException>(__FILE__, __LINE__, "OutOfRangeException" ).Report
00240 
00242     #define PROPERTY_EXCEPTION GenICam::ExceptionReporter<GenICam::PropertyException>(__FILE__, __LINE__, "PropertyException" ).Report
00243 
00245     #define RUNTIME_EXCEPTION GenICam::ExceptionReporter<GenICam::RuntimeException>(__FILE__, __LINE__, "RuntimeException" ).Report
00246 
00248     #define LOGICAL_ERROR_EXCEPTION GenICam::ExceptionReporter<GenICam::LogicalErrorException>(__FILE__,  __LINE__, "LogicalErrorException" ).Report
00249 
00251     #define ACCESS_EXCEPTION GenICam::ExceptionReporter<GenICam::AccessException>(__FILE__, __LINE__, "AccessException" ).Report
00252 
00254     #define TIMEOUT_EXCEPTION GenICam::ExceptionReporter<GenICam::TimeoutException>(__FILE__, __LINE__,"TimeoutException" ).Report
00255 
00257     #define DYNAMICCAST_EXCEPTION GenICam::ExceptionReporter<GenICam::DynamicCastException>(__FILE__, __LINE__, "DynamicCastException" ).Report
00258 
00260     #define CHECK_RANGE_I64(_Value, _Min, _Max, _Inc) \
00261         if((int64_t)(_Value) < (int64_t)(_Min)) \
00262             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)); \
00263                 else if((int64_t)(_Value) > (int64_t)(_Max)) \
00264             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)); \
00265                 else if ( 0 == _Inc ) \
00266             throw LOGICAL_ERROR_EXCEPTION("Increment must not equal 0!"); \
00267                 else if( ((int64_t)(_Value) - (int64_t)(_Min)) % (int64_t)(_Inc) != 0) \
00268             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));
00269 
00271     #define CHECK_RANGE_FLT(_Value, _Min, _Max) \
00272         if ((_Value) < (_Min)) \
00273             throw OUT_OF_RANGE_EXCEPTION( "Value %f must be greater than or equal %f", (_Value), (_Min) ); \
00274         else if ((_Value) > (_Max)) \
00275             throw OUT_OF_RANGE_EXCEPTION( "Value %f must be smaller than or equal %f", (_Value), (_Max) );
00276 
00278     #define CHECK_DYNAMIC_CAST_POINTER( _Pointer )\
00279         assert( (_Pointer) != NULL ); \
00280         if (NULL == (_Pointer)) throw LOGICAL_ERROR_EXCEPTION( "Unexpected type in dynamic cast" )
00281 
00283 
00284 }
00285 
00286 #pragma pack(pop)
00287 
00288 #endif // GENCAM_EXCEPTION_H_


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:02