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