gnException.h Source File

Main Page Namespace List Class Hierarchy Alphabetical List Compound List File List Compound Members File Members

# gnException.h

Go to the documentation of this file.

    00001 #ifndef _gnException_h_
    00002 #define _gnException_h_
    00003
    00004 #include "gnClone.h"
    00005 #include "gn/gnExceptionCode.h"
    00006 #include <string>
    00007 #include <list>
    00008
    00009 class GNDLLEXPORT gnException
    00010 {
    00011 public:
    00012         gnException( const char* const srcFile,
    00013                                  const unsigned int srcLine,
    00014                                  const char* const function,
    00015                                  gnExceptionCode& code,
    00016                                  const char* const message );
    00017
    00018         friend std::ostream& operator<<(std::ostream& os, const gnException& gne); //write to source.
    00019         gnExceptionCode& GetCode(){return m_code;}
    00020         string GetMessage(){return m_message;}
    00021         void AddCaller( const char* const function );
    00022 protected:
    00023         gnExceptionCode& m_code;
    00024         string m_message;
    00025         const char* const m_file;
    00026         unsigned int m_line;
    00027         list<string> function_trace;
    00028 };
    00029
    00030 inline
    00031 gnException::gnException(const char* const srcFile, const unsigned int srcLine, const char* const function, gnExceptionCode& code, const char* const message ) :
    00032 m_code(code), m_message(message), m_file(srcFile), m_line(srcLine){
    00033         AddCaller(function);
    00034 }
    00035
    00036
    00037 GNDLLEXPORT
    00038 std::ostream& operator<<(std::ostream& os, const gnException& gne); //write to source.
    00039
    00040
    00041 #ifdef __GNDEBUG__
    00042 #define STACK_TRACE_START try{
    00043 #define STACK_TRACE_END \
    00044 }catch(gnException& e){\
    00045         e.AddCaller(__PRETTY_FUNCTION__);\
    00046         throw e;\
    00047 }
    00048 #else
    00049 #define STACK_TRACE_START
    00050 #define STACK_TRACE_END
    00051 #endif // ifdef __DEBUG__
    00052
    00053 #define Throw_gnEx(code) throw gnException(__FILE__, __LINE__, __PRETTY_FUNCTION__, code, "")
    00054 #define Throw_gnExMsg(code,msg) throw gnException(__FILE__, __LINE__, __PRETTY_FUNCTION__, code, msg)
    00055 #endif //_gnException_h_