| API Docs for SAX and DOM |
| Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members File Members # XMLException.hpp Go to the documentation of this file.
    00001 /*
    00002  * The Apache Software License, Version 1.1
    00003  *
    00004  * Copyright (c) 1999-2000 The Apache Software Foundation.  All rights
    00005  * reserved.
    00006  *
    00007  * Redistribution and use in source and binary forms, with or without
    00008  * modification, are permitted provided that the following conditions
    00009  * are met:
    00010  *
    00011  * 1. Redistributions of source code must retain the above copyright
    00012  *    notice, this list of conditions and the following disclaimer.
    00013  *
    00014  * 2. Redistributions in binary form must reproduce the above copyright
    00015  *    notice, this list of conditions and the following disclaimer in
    00016  *    the documentation and/or other materials provided with the
    00017  *    distribution.
    00018  *
    00019  * 3. The end-user documentation included with the redistribution,
    00020  *    if any, must include the following acknowledgment:
    00021  *       "This product includes software developed by the
    00022  *        Apache Software Foundation (http://www.apache.org/)."
    00023  *    Alternately, this acknowledgment may appear in the software itself,
    00024  *    if and wherever such third-party acknowledgments normally appear.
    00025  *
    00026  * 4. The names "Xerces" and "Apache Software Foundation" must
    00027  *    not be used to endorse or promote products derived from this
    00028  *    software without prior written permission. For written
    00029  *    permission, please contact apache\@apache.org.
    00030  *
    00031  * 5. Products derived from this software may not be called "Apache",
    00032  *    nor may "Apache" appear in their name, without prior written
    00033  *    permission of the Apache Software Foundation.
    00034  *
    00035  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
    00036  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
    00037  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    00038  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
    00039  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    00040  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    00041  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
    00042  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    00043  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
    00044  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
    00045  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    00046  * SUCH DAMAGE.
    00047  * ====================================================================
    00048  *
    00049  * This software consists of voluntary contributions made by many
    00050  * individuals on behalf of the Apache Software Foundation, and was
    00051  * originally based on software copyright (c) 1999, International
    00052  * Business Machines, Inc., http://www.ibm.com .  For more information
    00053  * on the Apache Software Foundation, please see
    00054  * <http://www.apache.org/>.
    00055  */
    00056
    00057 /*
    00058  * $Id: XMLException.hpp,v 1.3 2002/12/04 02:32:43 knoaman Exp $
    00059  */
    00060
    00061 #if !defined(EXCEPTION_HPP)
    00062 #define EXCEPTION_HPP
    00063
    00064 #include <xercesc/util/XMLExceptMsgs.hpp>
    00065 #include <xercesc/util/XMLUni.hpp>
    00066 #include <xercesc/framework/XMLErrorReporter.hpp>
    00067
    00068 XERCES_CPP_NAMESPACE_BEGIN
    00069
    00070 // ---------------------------------------------------------------------------
    00071 //  This is the base class from which all the XML parser exceptions are
    00072 //  derived. The virtual interface is very simple and most of the functionality
    00073 //  is in this class.
    00074 //
    00075 //  Because all derivatives are EXACTLY the same except for the static
    00076 //  string that is used to hold the name of the class, a macro is provided
    00077 //  below via which they are all created.
    00078 // ---------------------------------------------------------------------------
    00079 class  XMLException
    00080 {
    00081 public:
    00082     // -----------------------------------------------------------------------
    00083     //  Virtual Destructor
    00084     // -----------------------------------------------------------------------
    00085     virtual ~XMLException();
    00086
    00087
    00088     // -----------------------------------------------------------------------
    00089     //  The XML exception virtual interface
    00090     // -----------------------------------------------------------------------
    00091     virtual const XMLCh* getType() const = 0;
    00092
    00093
    00094     // -----------------------------------------------------------------------
    00095     //  Getter methods
    00096     // -----------------------------------------------------------------------
    00097     XMLExcepts::Codes getCode() const;
    00098     const XMLCh* getMessage() const;
    00099     const char* getSrcFile() const;
    00100     unsigned int getSrcLine() const;
    00101     XMLErrorReporter::ErrTypes getErrorType() const;
    00102
    00103
    00104     // -----------------------------------------------------------------------
    00105     //  Setter methods
    00106     // -----------------------------------------------------------------------
    00107     void setPosition(const char* const file, const unsigned int line);
    00108
    00109
    00110     // -----------------------------------------------------------------------
    00111     //  Hidden constructors and operators
    00112     //
    00113     //  NOTE:   Technically, these should be protected, since this is a
    00114     //          base class that is never used directly. However, VC++ 6.0 will
    00115     //          fail to catch via a reference to base class if the ctors are
    00116     //          not public!! This seems to have been caused by the install
    00117     //          of IE 5.0.
    00118     // -----------------------------------------------------------------------
    00119     XMLException();
    00120     XMLException(const char* const srcFile, const unsigned int srcLine);
    00121     XMLException(const XMLException& toCopy);
    00122     void operator=(const XMLException& toAssign);
    00123
    00124     // -----------------------------------------------------------------------
    00125     //  Notification that lazy data has been deleted
    00126     // -----------------------------------------------------------------------
    00127     static void reinitMsgMutex();
    00128
    00129     static void reinitMsgLoader();
    00130
    00131 protected :
    00132     // -----------------------------------------------------------------------
    00133     //  Protected methods
    00134     // -----------------------------------------------------------------------
    00135     void loadExceptText
    00136     (
    00137         const   XMLExcepts::Codes toLoad
    00138     );
    00139     void loadExceptText
    00140     (
    00141         const   XMLExcepts::Codes toLoad
    00142         , const XMLCh* const        text1
    00143         , const XMLCh* const        text2 = 0
    00144         , const XMLCh* const        text3 = 0
    00145         , const XMLCh* const        text4 = 0
    00146     );
    00147     void loadExceptText
    00148     (
    00149         const   XMLExcepts::Codes toLoad
    00150         , const char* const         text1
    00151         , const char* const         text2 = 0
    00152         , const char* const         text3 = 0
    00153         , const char* const         text4 = 0
    00154     );
    00155
    00156
    00157 private :
    00158     // -----------------------------------------------------------------------
    00159     //  Data members
    00160     //
    00161     //  fCode
    00162     //      The error code that this exception represents.
    00163     //
    00164     //  fSrcFile
    00165     //  fSrcLine
    00166     //      These are the file and line information from the source where the
    00167     //      exception was thrown from.
    00168     //
    00169     //  fMsg
    00170     //      The loaded message text for this exception.
    00171     // -----------------------------------------------------------------------
    00172     XMLExcepts::Codes fCode;
    00173     char*               fSrcFile;
    00174     unsigned int        fSrcLine;
    00175     XMLCh*              fMsg;
    00176 };
    00177
    00178 // ---------------------------------------------------------------------------
    00179 //  XMLException: Getter methods
    00180 // ---------------------------------------------------------------------------
    00181 inline XMLExcepts::Codes XMLException::getCode() const
    00182 {
    00183     return fCode;
    00184 }
    00185
    00186 inline const XMLCh* XMLException::getMessage() const
    00187 {
    00188     return fMsg;
    00189 }
    00190
    00191 inline const char* XMLException::getSrcFile() const
    00192 {
    00193     if (!fSrcFile)
    00194         return "";
    00195     return fSrcFile;
    00196 }
    00197
    00198 inline unsigned int XMLException::getSrcLine() const
    00199 {
    00200     return fSrcLine;
    00201 }
    00202
    00203 inline XMLErrorReporter::ErrTypes XMLException::getErrorType() const
    00204 {
    00205    if ((fCode >= XMLExcepts::W_LowBounds) && (fCode <= XMLExcepts::W_HighBounds))
    00206        return XMLErrorReporter::ErrType_Warning;
    00207    else if ((fCode >= XMLExcepts::F_LowBounds) && (fCode <= XMLExcepts::F_HighBounds))
    00208         return XMLErrorReporter::ErrType_Fatal;
    00209    else if ((fCode >= XMLExcepts::E_LowBounds) && (fCode <= XMLExcepts::E_HighBounds))
    00210         return XMLErrorReporter::ErrType_Error;
    00211    return XMLErrorReporter::ErrTypes_Unknown;
    00212 }
    00213
    00214 // ---------------------------------------------------------------------------
    00215 //  This macro is used to create derived classes. They are all identical
    00216 //  except the name of the exception, so it crazy to type them in over and
    00217 //  over.
    00218 // ---------------------------------------------------------------------------
    00219 #define MakeXMLException(theType, expKeyword) \
    00220 class expKeyword theType : public XMLException \
    00221 { \
    00222 public: \
    00223  \
    00224     theType(const   char* const         srcFile \
    00225             , const unsigned int        srcLine \
    00226             , const XMLExcepts::Codes toThrow) : \
    00227         XMLException(srcFile, srcLine) \
    00228     { \
    00229         loadExceptText(toThrow); \
    00230     } \
    00231  \
    00232     theType(const theType& toCopy) : \
    00233  \
    00234         XMLException(toCopy) \
    00235     { \
    00236     } \
    00237   \
    00238     theType(const   char* const         srcFile \
    00239             , const unsigned int        srcLine \
    00240             , const XMLExcepts::Codes toThrow \
    00241             , const XMLCh* const        text1 \
    00242             , const XMLCh* const        text2 = 0 \
    00243             , const XMLCh* const        text3 = 0 \
    00244             , const XMLCh* const        text4 = 0) : \
    00245         XMLException(srcFile, srcLine) \
    00246     { \
    00247         loadExceptText(toThrow, text1, text2, text3, text4); \
    00248     } \
    00249  \
    00250     theType(const   char* const         srcFile \
    00251             , const unsigned int        srcLine \
    00252             , const XMLExcepts::Codes toThrow \
    00253             , const char* const         text1 \
    00254             , const char* const         text2 = 0 \
    00255             , const char* const         text3 = 0 \
    00256             , const char* const         text4 = 0) : \
    00257         XMLException(srcFile, srcLine) \
    00258     { \
    00259         loadExceptText(toThrow, text1, text2, text3, text4); \
    00260     } \
    00261  \
    00262     virtual ~theType() {} \
    00263  \
    00264     theType& operator=(const theType& toAssign) \
    00265     { \
    00266         XMLException::operator=(toAssign); \
    00267         return *this; \
    00268     } \
    00269  \
    00270     virtual XMLException* duplicate() const \
    00271     { \
    00272         return new theType(*this); \
    00273     } \
    00274  \
    00275     virtual const XMLCh* getType() const \
    00276     { \
    00277         return XMLUni::fg##theType##_Name; \
    00278     } \
    00279  \
    00280 private : \
    00281     theType(); \
    00282 };
    00283
    00284
    00285
    00286 // ---------------------------------------------------------------------------
    00287 //  This macros is used to actually throw an exception. It is used in order
    00288 //  to make sure that source code line/col info is stored correctly, and to
    00289 //  give flexibility for other stuff in the future.
    00290 // ---------------------------------------------------------------------------
    00291 #define ThrowXML(type,code) throw type(__FILE__, __LINE__, code)
    00292
    00293 #define ThrowXML1(type,code,p1) throw type(__FILE__, __LINE__, code, p1)
    00294
    00295 #define ThrowXML2(type,code,p1,p2) throw type(__FILE__, __LINE__, code, p1, p2)
    00296
    00297 #define ThrowXML3(type,code,p1,p2,p3) throw type(__FILE__, __LINE__, code, p1, p2, p3)
    00298
    00299 #define ThrowXML4(type,code,p1,p2,p3,p4) throw type(__FILE__, __LINE__, code, p1, p2, p3, p4)
    00300
    00301 XERCES_CPP_NAMESPACE_END
    00302
    00303 #endif

Copyright © 2000 The Apache Software Foundation. All Rights Reserved.