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

Home

Readme
Installation
Build

API Docs
Samples
Programming
Migration
FAQs

Releases
Feedback
Bug-Todo

Download
CVS Repository
Mail Archive

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.5 2000/05/04 02:43:45 aruna1 Exp $

00059  */
00060 
00061 #if !defined(EXCEPTION_HPP)
00062 #define EXCEPTION_HPP
00063 
00064 #include <util/XercesDefs.hpp>
00065 #include <util/XMLExceptMsgs.hpp>
00066 #include <util/XMLUni.hpp>
00067 
00068 
00069 // ---------------------------------------------------------------------------
00070 //  This is the base class from which all the XML parser exceptions are
00071 //  derived. The virtual interface is very simple and most of the functionality
00072 //  is in this class.
00073 //
00074 //  Because all derivatives are EXACTLY the same except for the static
00075 //  string that is used to hold the name of the class, a macro is provided
00076 //  below via which they are all created.
00077 // ---------------------------------------------------------------------------
00078 class  XMLException
00079 {
00080 public:
00081     // -----------------------------------------------------------------------
00082     //  Virtual Destructor
00083     // -----------------------------------------------------------------------
00084     virtual ~XMLException();
00085 
00086 
00087     // -----------------------------------------------------------------------
00088     //  The XML exception virtual interface
00089     // -----------------------------------------------------------------------
00090     virtual const XMLCh* getType() const = 0;
00091 
00092 
00093     // -----------------------------------------------------------------------
00094     //  Getter methods
00095     // -----------------------------------------------------------------------
00096     XMLExcepts::Codes getCode() const;
00097     const XMLCh* getMessage() const;
00098     const char* getSrcFile() const;
00099     unsigned int getSrcLine() const;
00100 
00101 
00102     // -----------------------------------------------------------------------
00103     //  Setter methods
00104     // -----------------------------------------------------------------------
00105     void setPosition(const char* const file, const unsigned int line);
00106 
00107 
00108     // -----------------------------------------------------------------------
00109     //  Hidden constructors and operators
00110     //
00111     //  NOTE:   Technically, these should be protected, since this is a
00112     //          base class that is never used directly. However, VC++ 6.0 will
00113     //          fail to catch via a reference to base class if the ctors are
00114     //          not public!! This seems to have been caused by the install
00115     //          of IE 5.0.
00116     // -----------------------------------------------------------------------
00117     XMLException();
00118     XMLException(const char* const srcFile, const unsigned int srcLine);
00119     XMLException(const XMLException& toCopy);
00120     void operator=(const XMLException& toAssign);
00121 
00122 
00123 protected :
00124     // -----------------------------------------------------------------------
00125     //  Protected methods
00126     // -----------------------------------------------------------------------
00127     void loadExceptText
00128     (
00129         const   XMLExcepts::Codes toLoad
00130     );
00131     void loadExceptText
00132     (
00133         const   XMLExcepts::Codes toLoad
00134         , const XMLCh* const        text1
00135         , const XMLCh* const        text2 = 0
00136         , const XMLCh* const        text3 = 0
00137         , const XMLCh* const        text4 = 0
00138     );
00139     void loadExceptText
00140     (
00141         const   XMLExcepts::Codes toLoad
00142         , const char* const         text1
00143         , const char* const         text2 = 0
00144         , const char* const         text3 = 0
00145         , const char* const         text4 = 0
00146     );
00147 
00148 
00149 private :
00150     // -----------------------------------------------------------------------
00151     //  Data members
00152     //
00153     //  fCode
00154     //      The error code that this exception represents.
00155     //
00156     //  fSrcFile
00157     //  fSrcLine
00158     //      These are the file and line information from the source where the
00159     //      exception was thrown from.
00160     //
00161     //  fMsg
00162     //      The loaded message text for this exception.
00163     // -----------------------------------------------------------------------
00164     XMLExcepts::Codes fCode;
00165     char*               fSrcFile;
00166     unsigned int        fSrcLine;
00167     XMLCh*              fMsg;
00168 };
00169 
00170 // ---------------------------------------------------------------------------
00171 //  XMLException: Getter methods
00172 // ---------------------------------------------------------------------------
00173 inline XMLExcepts::Codes XMLException::getCode() const

00174 {
00175     return fCode;
00176 }
00177 
00178 inline const XMLCh* XMLException::getMessage() const

00179 {
00180     return fMsg;
00181 }
00182 
00183 inline const char* XMLException::getSrcFile() const

00184 {
00185     if (!fSrcFile)
00186         return "";
00187     return fSrcFile;
00188 }
00189 
00190 inline unsigned int XMLException::getSrcLine() const

00191 {
00192     return fSrcLine;
00193 }
00194 
00195 
00196 // ---------------------------------------------------------------------------
00197 //  This macro is used to create derived classes. They are all identical
00198 //  except the name of the exception, so it crazy to type them in over and
00199 //  over.
00200 // ---------------------------------------------------------------------------
00201 #define MakeXMLException(theType, expKeyword) \

00202 class expKeyword theType : public XMLException \

00203 { \

00204 public: \

00205  \

00206     theType(const   char* const         srcFile \

00207             , const unsigned int        srcLine \

00208             , const XMLExcepts::Codes toThrow) : \

00209         XMLException(srcFile, srcLine) \

00210     { \

00211         loadExceptText(toThrow); \

00212     } \

00213  \

00214     theType(const theType& toCopy) : \

00215  \

00216         XMLException(toCopy) \

00217     { \

00218     } \

00219   \

00220     theType(const   char* const         srcFile \

00221             , const unsigned int        srcLine \

00222             , const XMLExcepts::Codes toThrow \

00223             , const XMLCh* const        text1 \

00224             , const XMLCh* const        text2 = 0 \

00225             , const XMLCh* const        text3 = 0 \

00226             , const XMLCh* const        text4 = 0) : \

00227         XMLException(srcFile, srcLine) \

00228     { \

00229         loadExceptText(toThrow, text1, text2, text3, text4); \

00230     } \

00231  \

00232     theType(const   char* const         srcFile \

00233             , const unsigned int        srcLine \

00234             , const XMLExcepts::Codes toThrow \

00235             , const char* const         text1 \

00236             , const char* const         text2 = 0 \

00237             , const char* const         text3 = 0 \

00238             , const char* const         text4 = 0) : \

00239         XMLException(srcFile, srcLine) \

00240     { \

00241         loadExceptText(toThrow, text1, text2, text3, text4); \

00242     } \

00243  \

00244     virtual ~theType() {} \

00245  \

00246     theType& operator=(const theType& toAssign) \

00247     { \

00248         XMLException::operator=(toAssign); \

00249         return *this; \

00250     } \

00251  \

00252     virtual XMLException* duplicate() const \

00253     { \

00254         return new theType(*this); \

00255     } \

00256  \

00257     virtual const XMLCh* getType() const \

00258     { \

00259         return XMLUni::fg##theType##_Name; \

00260     } \

00261  \

00262 private : \

00263     theType(); \

00264 };
00265 
00266 
00267 
00268 // ---------------------------------------------------------------------------
00269 //  This macros is used to actually throw an exception. It is used in order
00270 //  to make sure that source code line/col info is stored correctly, and to
00271 //  give flexibility for other stuff in the future.
00272 // ---------------------------------------------------------------------------
00273 #define ThrowXML(type,code) throw type(__FILE__, __LINE__, code)
00274 
00275 #define ThrowXML1(type,code,p1) throw type(__FILE__, __LINE__, code, p1)
00276 
00277 #define ThrowXML2(type,code,p1,p2) throw type(__FILE__, __LINE__, code, p1, p2)
00278 
00279 #define ThrowXML3(type,code,p1,p2,p3) throw type(__FILE__, __LINE__, code, p1, p2, p3)
00280 
00281 #define ThrowXML4(type,code,p1,p2,p3,p4) throw type(__FILE__, __LINE__, code, p1, p2, p3, p4)
00282 
00283 #endif


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