00001 #ifndef __CHM_ERROR_CLASS_H__
00002 #define __CHM_ERROR_CLASS_H__
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <CHM/CHMminimumInclude.h>
00016 class CHMstring;
00017
00018 const long CHM_BAD_VERSION = 123112;
00019
00020 #ifdef _MFC_VER
00021 #define _USE_MFC_EXCEPTIONS
00022 #endif
00023
00024 #if defined(_USE_MFC_EXCEPTIONS)
00025 #include <afx.h>
00026
00027 class CHMerror : public CException
00028 {
00029 DECLARE_DYNAMIC(CHMerror)
00030 public:
00031 CHMerror(const CHMchar* Message, long Line, const char* File, long Code);
00032 CHMerror(const CHMresult Code, long Line, const char* File);
00033 CHMerror(const CHMerror& Orig);
00034
00035 virtual ~CHMerror();
00036
00037
00038
00039 virtual BOOL GetErrorMessage(LPTSTR lpszError, UINT nMaxError,
00040 PUINT pnHelpContext = NULL);
00041 const long Code() const;
00042 CHMchar* Description() const;
00043 const char* Parameter(const CHMchar* pKey) const;
00044
00045
00046
00047
00048
00052 CHMstring Dump() const;
00053
00054
00055
00056
00057 protected:
00058 CHMchar* m_pDescription;
00059 long m_Code;
00060 long m_Line;
00061 char* m_File;
00062 CHMreferenceHandle m_Handle;
00063 private:
00064 CHMerror& operator=(const CHMerror& Error);
00065 };
00066
00067 #else
00075 class CHMerror
00076 {
00077 public:
00078 CHMerror(const CHMchar* Message, long Line, const char* File, long Code);
00079 CHMerror(const CHMerror& Error);
00080 CHMerror(const CHMresult Handle, long Line, const char* File);
00081 virtual ~CHMerror();
00082
00084 const long Code() const;
00085
00087 unsigned int CountOfParameter() const;
00088
00090 CHMchar* Description() const;
00091
00095 CHMstring Dump() const;
00096
00098 CHMboolean HasParameter(const CHMchar* pKey) const;
00099
00101 const char* Parameter(const CHMchar* pKey) const;
00102
00104 const char* ParameterName(unsigned int Index) const;
00105
00106
00107
00108
00109
00110
00111
00112 protected:
00113 CHMchar* m_pDescription;
00114 long m_Code;
00115 long m_Line;
00116 char* m_File;
00117 CHMreferenceHandle m_Handle;
00118 private:
00119 CHMerror& operator=(const CHMerror& Error);
00120 };
00121 #endif // end of defining compilation of error determined by the type of
00122
00123
00124
00125
00126
00127
00131 void CHMactivateCondition(const CHMchar* Message, long Line, const char* File, CHMresult Code);
00135 void CHMactivateCondition(const CHMchar* Message, long Line, const char* File);
00136
00137 #if defined(WIN32) && defined(CHM_64)
00138 #define CHM_CHECK_CALL(x) { CHMresult Result = x; if (Result != CHM_OK) { CHMactivateCondition(CHM_TEXT(#x), __LINE__, __FILE__, Result); } }
00139 #else
00140 #define CHM_CHECK_CALL(x) { CHMresult Result = _##x; if (Result != CHM_OK) { CHMactivateCondition(CHM_TEXT(#x), __LINE__, __FILE__, Result); } }
00141 #endif
00142
00143 #define CHM_ASSERT(x) if (!(x)) { CHMactivateCondition(CHM_TEXT(#x), __LINE__, __FILE__); }
00144
00145 #define CHM_ASSERT_COMMENT(x, y) if (!(x)) { CHMactivateCondition(CHM_TEXT(y), __LINE__, __FILE__); }
00146
00147 #define CHM_HANDLE_UNKNOWN_MESSAGE throw CHMerror(CHM_TEXT("Unknown message encountered."), __LINE__, __FILE__, 0);
00148
00149 #ifndef CHMPRECONDITION
00150 # define CHMPRECONDITION(x) CHM_ASSERT(#x)
00151 #endif
00152
00153 #endif // end of defensive include