http://xml.apache.org/http://www.apache.org/http://www.w3.org/

Home

Readme
Charter
Release Info

Installation
Download
Build Instructions

FAQs
Samples
API Docs

DOM C++ Binding
Programming
Migration Guide

Feedback
Bug-Reporting
PDF Document

Source Repository
User Mail Archive
Devel Mail Archive

API Docs for SAX and DOM
 

XMLException.hpp

Go to the documentation of this file.
00001 /*
00002  * Copyright 1999-2000,2004 The Apache Software Foundation.
00003  * 
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  * 
00008  *      http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 /*
00018  * $Id: XMLException.hpp 176026 2004-09-08 13:57:07Z peiyongz $
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 //  This is the base class from which all the XML parser exceptions are
00033 //  derived. The virtual interface is very simple and most of the functionality
00034 //  is in this class.
00035 //
00036 //  Because all derivatives are EXACTLY the same except for the static
00037 //  string that is used to hold the name of the class, a macro is provided
00038 //  below via which they are all created.
00039 // ---------------------------------------------------------------------------
00040 class  XMLException : public XMemory
00041 {
00042 public:
00043     // -----------------------------------------------------------------------
00044     //  Virtual Destructor
00045     // -----------------------------------------------------------------------
00046     virtual ~XMLException();
00047 
00048 
00049     // -----------------------------------------------------------------------
00050     //  The XML exception virtual interface
00051     // -----------------------------------------------------------------------
00052     virtual const XMLCh* getType() const = 0;
00053 
00054 
00055     // -----------------------------------------------------------------------
00056     //  Getter methods
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     //  Setter methods
00067     // -----------------------------------------------------------------------
00068     void setPosition(const char* const file, const unsigned int line);
00069 
00070 
00071     // -----------------------------------------------------------------------
00072     //  Hidden constructors and operators
00073     //
00074     //  NOTE:   Technically, these should be protected, since this is a
00075     //          base class that is never used directly. However, VC++ 6.0 will
00076     //          fail to catch via a reference to base class if the ctors are
00077     //          not public!! This seems to have been caused by the install
00078     //          of IE 5.0.
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     //  Notification that lazy data has been deleted
00087     // -----------------------------------------------------------------------
00088     static void reinitMsgMutex();
00089 
00090     static void reinitMsgLoader();
00091 
00092 protected :
00093     // -----------------------------------------------------------------------
00094     //  Protected methods
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     //  Data members
00121     //
00122     //  fCode
00123     //      The error code that this exception represents.
00124     //
00125     //  fSrcFile
00126     //  fSrcLine
00127     //      These are the file and line information from the source where the
00128     //      exception was thrown from.
00129     //
00130     //  fMsg
00131     //      The loaded message text for this exception.
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 //  XMLException: Getter methods
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 //  This macro is used to create derived classes. They are all identical
00180 //  except the name of the exception, so it crazy to type them in over and
00181 //  over.
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 //  This macros is used to actually throw an exception. It is used in order
00255 //  to make sure that source code line/col info is stored correctly, and to
00256 //  give flexibility for other stuff in the future.
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


Copyright © 1994-2004 The Apache Software Foundation. All Rights Reserved.