exception.h

Go to the documentation of this file.
00001 /*
00002  * Copyright 2006-2008 The FLWOR 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 #ifndef ZORBA_EXCEPTION_API_H
00017 #define ZORBA_EXCEPTION_API_H
00018 
00019 #include <zorba/config.h>
00020 #include <zorba/error.h>
00021 #include <zorba/zorbastring.h>
00022 
00023 namespace zorba {
00024 
00025 /** \brief Base class of all exceptions thrown by %Zorba.
00026  */
00027 class ZORBA_EXTERN_DECL ZorbaException
00028 {
00029  public:
00030   /** \brief Destructor
00031    */
00032   virtual ~ZorbaException() throw();
00033 
00034   /** \brief Get the ErrorCode of the error that is reported by this exception.
00035    */
00036   virtual XQUERY_ERROR
00037   getErrorCode() const;
00038 
00039 
00040   /** \brief Get the descriptionof the error that is reported by this exception.
00041    */
00042   virtual String
00043   getDescription() const;
00044 
00045   /** \brief Get the name of the source file in which the error occured.
00046    *
00047    * Note that this information is mainly for debugging purposes.
00048    *
00049    * @return String the name of the file where the error occured.
00050    */
00051   virtual String
00052   getFileName() const;
00053 
00054   /** \brief Get the line number in the source file in which the error occured.
00055    *
00056    * Note that this information is mainly for debugging purposes.
00057    *
00058    * @return unsigned int the line number in the source file.
00059    */
00060   virtual unsigned int
00061   getFileLineNumber() const;
00062 
00063 
00064   /** \brief Static function to convert an XQUERY_ERROR to a String
00065    *
00066    * @param  aErrorCode the XQUERY_ERROR to convert to a String.
00067    * @return String the String representation of the XQUERY_ERROR.
00068    */
00069   static std::string
00070   getErrorCodeAsString(const XQUERY_ERROR& aErrorCode);
00071 
00072 protected:
00073   friend class ZorbaImpl;
00074   /** \brief Proctected constructor - only the %Zorba engine can construct and throw
00075    *         exceptions.
00076    */
00077   ZorbaException(const XQUERY_ERROR&, const String& aDescription,
00078                  const String& aFileName, unsigned int aFileLineNumber);
00079 
00080   XQUERY_ERROR   theErrorCode;
00081   String         theDescription;
00082   String         theFileName;
00083   unsigned int   theFileLineNumber;          
00084 };
00085 
00086 
00087 /** \brief QueryException is the base class for all errors that occur during query processing
00088  *         and have a direct connection to the query, i.e. information about the location
00089  *         where the error occured in the query is available.
00090  */
00091 class ZORBA_EXTERN_DECL QueryException : public ZorbaException 
00092 {
00093  public:
00094   /** \brief Destructor
00095    */
00096   virtual ~QueryException() throw();
00097 
00098   /** \brief Get the line number in the query where the error occured.
00099    *
00100    * @return unsigned int the line number in the query.
00101    */
00102   virtual unsigned int
00103   getLineBegin() const;
00104 
00105   /** \brief Get the column number in the query where the error occured.
00106    *
00107    * @return unsigned int the column number in the query.
00108    */
00109   virtual unsigned int
00110   getColumnBegin() const;
00111 
00112   /** \brief Get the uri of the query where the error occured.
00113    *
00114    * @return String the uri of the query
00115    */
00116   virtual String
00117   getQueryURI() const;
00118 
00119 protected:
00120   friend ZORBA_EXTERN_DECL std::ostream& operator<<(std::ostream&, const QueryException&);
00121   friend class ZorbaImpl;
00122 
00123   /** \brief Proctected constructor - only the %Zorba engine can construct and throw
00124    *         exceptions.
00125    */
00126   QueryException(
00127         const XQUERY_ERROR&,
00128         const String& aDescription, 
00129         const String& afilename,
00130         unsigned int afilelinenumber,
00131         const String& queryuri,
00132         unsigned int linebegin,
00133         unsigned int columnbegin);
00134 
00135 protected:
00136   unsigned int          theLineBegin;
00137   unsigned int          theColumnBegin;
00138   String                theQueryURI;
00139 };
00140 
00141 
00142 /** \brief DynamicException represents a dynamic error as defined in the %XQuery 1.0
00143  *         Specification (see http://www.w3.org/TR/xquery/#id-kinds-of-errors).
00144  */
00145 class ZORBA_EXTERN_DECL DynamicException : public QueryException
00146 {
00147   friend ZORBA_EXTERN_DECL std::ostream& operator<<(std::ostream&, const DynamicException&);
00148   friend class ZorbaImpl;
00149 
00150 public:
00151   /** \brief Destructor
00152    */
00153   virtual ~DynamicException() throw();
00154 
00155 protected:
00156   /** \brief Proctected constructor - only the %Zorba engine can construct and throw
00157    *         exceptions.
00158    */
00159   DynamicException(
00160         const XQUERY_ERROR&,
00161         const String&,
00162         const String& afilename,
00163         unsigned int afilelinenumber,
00164         const String& queryuri,
00165         unsigned int linebegin,
00166         unsigned int columnbegin);
00167 };
00168 
00169 
00170 /** \brief StaticException represents a static error as defined in the %XQuery 1.0
00171  *         Specification (see http://www.w3.org/TR/xquery/#id-kinds-of-errors).
00172  */
00173 class ZORBA_EXTERN_DECL StaticException : public QueryException
00174 {
00175   friend ZORBA_EXTERN_DECL std::ostream& operator<<(std::ostream&, const StaticException&);
00176   friend class ZorbaImpl;
00177 
00178 
00179 public:
00180   /** \brief Destructor
00181    */
00182   virtual ~StaticException() throw();
00183 
00184 protected:
00185   /** \brief Proctected constructor - only the %Zorba engine can construct and throw
00186    *         exceptions.
00187    */
00188   StaticException(
00189         const XQUERY_ERROR&,
00190         const String&,
00191         const String& afilename,
00192         unsigned int afilelinenumber,
00193         const String& queryuri,
00194         unsigned int linebegin,
00195         unsigned int columnbegin);
00196 };
00197 
00198 
00199 /** \brief TypeException represents a type error as defined in the %XQuery 1.0
00200  *         Specification (see http://www.w3.org/TR/xquery/#id-kinds-of-errors).
00201  */
00202 class ZORBA_EXTERN_DECL TypeException : public QueryException
00203 {
00204   friend ZORBA_EXTERN_DECL std::ostream& operator<<(std::ostream&, const TypeException&);
00205   friend class ZorbaImpl;
00206 
00207 
00208 public:
00209   /** \brief Destructor
00210    */
00211   virtual ~TypeException() throw();
00212 
00213 protected:
00214   /** \brief Proctected constructor - only the %Zorba engine can construct and throw
00215    *         exceptions.
00216    */
00217   TypeException(
00218         const XQUERY_ERROR&,
00219         const String&,
00220         const String& afilename,
00221         unsigned int afilelinenumber,
00222         const String& queryuri,
00223         unsigned int linebegin,
00224         unsigned int columnbegin);
00225 
00226 };
00227 
00228 
00229 /** \brief SerializationException represents a serialization error as defined in the 
00230  *         XSLT 2.0 and XQuery 1.0 Serialization Specification 
00231  *         (see http://www.w3.org/TR/2005/CR-xslt-xquery-serialization-20051103/)
00232  */
00233 class ZORBA_EXTERN_DECL SerializationException : public QueryException
00234 {
00235   friend ZORBA_EXTERN_DECL std::ostream& operator<<(std::ostream&, const SerializationException&);
00236   friend class ZorbaImpl;
00237 
00238 public:
00239   /** \brief Destructor
00240    */
00241   virtual ~SerializationException() throw();
00242 
00243 protected:
00244   /** \brief Proctected constructor - only the %Zorba engine can construct and throw
00245    *         exceptions.
00246    */
00247   SerializationException(
00248         const XQUERY_ERROR&,
00249         const String& aDescription,
00250         const String& afilename,
00251         unsigned int afilelinenumber,
00252         const String& queryuri,
00253         unsigned int linebegin,
00254         unsigned int columnbegin);
00255 
00256 };
00257 
00258 
00259 /** \brief SystemException represents an error that occurs in the %Zorba system.
00260  */
00261 class ZORBA_EXTERN_DECL SystemException : public ZorbaException
00262 {
00263   friend ZORBA_EXTERN_DECL std::ostream& operator<<(std::ostream&, const ZorbaException&);
00264   friend class ZorbaImpl;
00265   friend class Item;
00266 
00267 public:
00268   /** \brief Destructor
00269    */
00270   virtual ~SystemException() throw();
00271 
00272 protected:
00273   /** \brief Proctected constructor - only the %Zorba engine can construct and throw
00274    *         exceptions.
00275    */
00276   SystemException(const XQUERY_ERROR&, const String& aDescription,
00277                   const String& afilename, unsigned int afilelinenumber);
00278 
00279 };
00280 
00281 
00282 /** \brief Print information about the exception to the given output stream */
00283 ZORBA_EXTERN_DECL
00284 std::ostream& operator<< (std::ostream& os, const ZorbaException& aException);
00285 /** \brief Print information about the exception to the given output stream */
00286 ZORBA_EXTERN_DECL
00287 std::ostream& operator<< (std::ostream& os, const QueryException& aException);
00288 /** \brief Print information about the exception to the given output stream */
00289 ZORBA_EXTERN_DECL
00290 std::ostream& operator<< (std::ostream& os, const StaticException& aException);
00291 /** \brief Print information about the exception to the given output stream */
00292 ZORBA_EXTERN_DECL
00293 std::ostream& operator<< (std::ostream& os, const DynamicException& aException);
00294 /** \brief Print information about the exception to the given output stream */
00295 ZORBA_EXTERN_DECL
00296 std::ostream& operator<< (std::ostream& os, const TypeException& aException);
00297 /** \brief Print information about the exception to the given output stream */
00298 ZORBA_EXTERN_DECL
00299 std::ostream& operator<< (std::ostream& os, const SerializationException& aException);
00300 /** \brief Print information about the exception to the given output stream */
00301 ZORBA_EXTERN_DECL
00302 std::ostream& operator<< (std::ostream& os, const SystemException& aException);
00303 
00304 } /* namespace zorba */
00305 #endif