00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #if !defined(EXCEPTION_HPP)
00023 #define EXCEPTION_HPP
00024
00025 #include <xercesc/util/XMemory.hpp>
00026 #include <xercesc/util/XMLExceptMsgs.hpp>
00027 #include <xercesc/util/XMLUni.hpp>
00028 #include <xercesc/framework/XMLErrorReporter.hpp>
00029
00030 XERCES_CPP_NAMESPACE_BEGIN
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 class XMLException : public XMemory
00042 {
00043 public:
00044
00045
00046
00047 virtual ~XMLException();
00048
00049
00050
00051
00052
00053 virtual const XMLCh* getType() const = 0;
00054
00055
00056
00057
00058
00059 XMLExcepts::Codes getCode() const;
00060 const XMLCh* getMessage() const;
00061 const char* getSrcFile() const;
00062 unsigned int getSrcLine() const;
00063 XMLErrorReporter::ErrTypes getErrorType() const;
00064
00065
00066
00067
00068
00069 void setPosition(const char* const file, const unsigned int line);
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 XMLException();
00082 XMLException(const char* const srcFile, const unsigned int srcLine, MemoryManager* const memoryManager = 0);
00083 XMLException(const XMLException& toCopy);
00084 XMLException& operator=(const XMLException& toAssign);
00085
00086
00087
00088
00089 static void reinitMsgMutex();
00090
00091 static void reinitMsgLoader();
00092
00093 protected :
00094
00095
00096
00097 void loadExceptText
00098 (
00099 const XMLExcepts::Codes toLoad
00100 );
00101 void loadExceptText
00102 (
00103 const XMLExcepts::Codes toLoad
00104 , const XMLCh* const text1
00105 , const XMLCh* const text2 = 0
00106 , const XMLCh* const text3 = 0
00107 , const XMLCh* const text4 = 0
00108 );
00109 void loadExceptText
00110 (
00111 const XMLExcepts::Codes toLoad
00112 , const char* const text1
00113 , const char* const text2 = 0
00114 , const char* const text3 = 0
00115 , const char* const text4 = 0
00116 );
00117
00118
00119 private :
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134 XMLExcepts::Codes fCode;
00135 char* fSrcFile;
00136 unsigned int fSrcLine;
00137 XMLCh* fMsg;
00138
00139 protected:
00140 MemoryManager* fMemoryManager;
00141 };
00142
00143
00144
00145
00146 inline XMLExcepts::Codes XMLException::getCode() const
00147 {
00148 return fCode;
00149 }
00150
00151 inline const XMLCh* XMLException::getMessage() const
00152 {
00153 return fMsg;
00154 }
00155
00156 inline const char* XMLException::getSrcFile() const
00157 {
00158 if (!fSrcFile)
00159 return "";
00160 return fSrcFile;
00161 }
00162
00163 inline unsigned int XMLException::getSrcLine() const
00164 {
00165 return fSrcLine;
00166 }
00167
00168 inline XMLErrorReporter::ErrTypes XMLException::getErrorType() const
00169 {
00170 if ((fCode >= XMLExcepts::W_LowBounds) && (fCode <= XMLExcepts::W_HighBounds))
00171 return XMLErrorReporter::ErrType_Warning;
00172 else if ((fCode >= XMLExcepts::F_LowBounds) && (fCode <= XMLExcepts::F_HighBounds))
00173 return XMLErrorReporter::ErrType_Fatal;
00174 else if ((fCode >= XMLExcepts::E_LowBounds) && (fCode <= XMLExcepts::E_HighBounds))
00175 return XMLErrorReporter::ErrType_Error;
00176 return XMLErrorReporter::ErrTypes_Unknown;
00177 }
00178
00179
00180
00181
00182
00183
00184 #define MakeXMLException(theType, expKeyword) \
00185 class expKeyword theType : public XMLException \
00186 { \
00187 public: \
00188 \
00189 theType(const char* const srcFile \
00190 , const unsigned int srcLine \
00191 , const XMLExcepts::Codes toThrow \
00192 , MemoryManager* memoryManager = 0) : \
00193 XMLException(srcFile, srcLine, memoryManager) \
00194 { \
00195 loadExceptText(toThrow); \
00196 } \
00197 \
00198 theType(const theType& toCopy) : \
00199 \
00200 XMLException(toCopy) \
00201 { \
00202 } \
00203 \
00204 theType(const char* const srcFile \
00205 , const unsigned int srcLine \
00206 , const XMLExcepts::Codes toThrow \
00207 , const XMLCh* const text1 \
00208 , const XMLCh* const text2 = 0 \
00209 , const XMLCh* const text3 = 0 \
00210 , const XMLCh* const text4 = 0 \
00211 , MemoryManager* memoryManager = 0) : \
00212 XMLException(srcFile, srcLine, memoryManager) \
00213 { \
00214 loadExceptText(toThrow, text1, text2, text3, text4); \
00215 } \
00216 \
00217 theType(const char* const srcFile \
00218 , const unsigned int srcLine \
00219 , const XMLExcepts::Codes toThrow \
00220 , const char* const text1 \
00221 , const char* const text2 = 0 \
00222 , const char* const text3 = 0 \
00223 , const char* const text4 = 0 \
00224 , MemoryManager* memoryManager = 0) : \
00225 XMLException(srcFile, srcLine, memoryManager) \
00226 { \
00227 loadExceptText(toThrow, text1, text2, text3, text4); \
00228 } \
00229 \
00230 virtual ~theType() {} \
00231 \
00232 theType& operator=(const theType& toAssign) \
00233 { \
00234 XMLException::operator=(toAssign); \
00235 return *this; \
00236 } \
00237 \
00238 virtual XMLException* duplicate() const \
00239 { \
00240 return new (fMemoryManager) theType(*this); \
00241 } \
00242 \
00243 virtual const XMLCh* getType() const \
00244 { \
00245 return XMLUni::fg##theType##_Name; \
00246 } \
00247 \
00248 private : \
00249 theType(); \
00250 };
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260 #define ThrowXML(type,code) throw type(__FILE__, __LINE__, code)
00261
00262 #define ThrowXML1(type,code,p1) throw type(__FILE__, __LINE__, code, p1)
00263
00264 #define ThrowXML2(type,code,p1,p2) throw type(__FILE__, __LINE__, code, p1, p2)
00265
00266 #define ThrowXML3(type,code,p1,p2,p3) throw type(__FILE__, __LINE__, code, p1, p2, p3)
00267
00268 #define ThrowXML4(type,code,p1,p2,p3,p4) throw type(__FILE__, __LINE__, code, p1, p2, p3, p4)
00269
00270 #define ThrowXMLwithMemMgr(type,code,memMgr) throw type(__FILE__, __LINE__, code, memMgr)
00271
00272 #define ThrowXMLwithMemMgr1(type,code,p1,memMgr) throw type(__FILE__, __LINE__, code, p1, 0, 0, 0, memMgr)
00273
00274 #define ThrowXMLwithMemMgr2(type,code,p1,p2,memMgr) throw type(__FILE__, __LINE__, code, p1, p2, 0, 0, memMgr)
00275
00276 #define ThrowXMLwithMemMgr3(type,code,p1,p2,p3,memMgr) throw type(__FILE__, __LINE__, code, p1, p2, p3, 0, memMgr)
00277
00278 #define ThrowXMLwithMemMgr4(type,code,p1,p2,p3,p4,memMgr) throw type(__FILE__, __LINE__, code, p1, p2, p3, p4, memMgr)
00279
00280 XERCES_CPP_NAMESPACE_END
00281
00282 #endif