Exception.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00029 #ifndef _GG_Exception_h_
00030 #define _GG_Exception_h_
00031
00032 #ifndef GG_API
00033 # ifdef _MSC_VER
00034 # define WIN32_LEAN_AND_MEAN
00035 # include <windows.h>
00036 # undef min
00037 # undef max
00038 # ifdef GiGi_EXPORTS
00039 # define GG_API __declspec(dllexport)
00040 # else
00041 # define GG_API __declspec(dllimport)
00042 # endif
00043 # else
00044 # define GG_API
00045 # endif
00046 #endif
00047
00048 #include <stdexcept>
00049 #include <string>
00050
00051
00052 namespace GG {
00053
00059 class GG_API ExceptionBase : public std::exception
00060 {
00061 public:
00062 ExceptionBase() throw() {}
00063 ExceptionBase(const std::string& msg) throw() : m_msg(msg) {}
00064 ~ExceptionBase() throw() {}
00065
00066 virtual const char* type() const throw() = 0;
00067 virtual const char* what() const throw() {return m_msg.c_str();}
00068
00069 private:
00070 std::string m_msg;
00071 };
00072
00075 #define GG_EXCEPTION( name ) \
00076 class GG_API name : public ExceptionBase \
00077 { \
00078 public: \
00079 name () throw() : ExceptionBase() {} \
00080 name (const std::string& msg) throw() : ExceptionBase(msg) {} \
00081 virtual const char* type() const throw() \
00082 {return "GG::" # name ;} \
00083 };
00084
00088 #define GG_ABSTRACT_EXCEPTION( name ) \
00089 class GG_API name : public ExceptionBase \
00090 { \
00091 public: \
00092 name () throw() : ExceptionBase() {} \
00093 name (const std::string& msg) throw() : ExceptionBase(msg) {} \
00094 virtual const char* type() const throw() = 0; \
00095 };
00096
00100 #define GG_CONCRETE_EXCEPTION( name, class_name, superclass ) \
00101 class GG_API name : public superclass \
00102 { \
00103 public: \
00104 name () throw() : superclass () {} \
00105 name (const std::string& msg) throw() : superclass (msg) {} \
00106 virtual const char* type() const throw() \
00107 {return # class_name "::" # name ;} \
00108 };
00109
00110 }
00111
00112 #endif // _GG_Enum_h_