xquery_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 
00017 #ifndef ZORBA_XQUERY_EXCEPTION_API_H
00018 #define ZORBA_XQUERY_EXCEPTION_API_H
00019 
00020 #include <zorba/xquery_stack_trace.h>
00021 #include <zorba/zorba_exception.h>
00022 
00023 namespace zorba {
00024 
00025 namespace serialization {
00026   class Archiver;
00027   void operator&( Archiver&, ZorbaException*& );
00028 }
00029 
00030 ///////////////////////////////////////////////////////////////////////////////
00031 
00032 /**
00033  * An %XQueryException is-a ZorbaException for errors with the user's XQuery.
00034  * An %XQueryException therefore also contains the XQuery source URI, line, and
00035  * column numbers.
00036  */
00037 class ZORBA_DLL_PUBLIC XQueryException : public ZorbaException {
00038 public:
00039   typedef internal::diagnostic::location::column_type column_type;
00040 
00041   /**
00042    * Copy-constructs an %XQueryException.
00043    *
00044    * @param from The %XQueryException to copy from.
00045    */
00046   XQueryException( XQueryException const &from );
00047 
00048   /**
00049    * Destroys this %XQueryException.
00050    */
00051   ~XQueryException() throw();
00052 
00053   /**
00054    * Assigns this %XQueryException from another.
00055    *
00056    * @param from The %XQueryException to assign from.
00057    * @return Returns \c *this.
00058    */
00059   XQueryException& operator=( XQueryException const &from );
00060 
00061   /**
00062    * Sets the XQuery source-code URI name, line, and column numbers.
00063    *
00064    * @param uri The source-code URI name.
00065    * @param line The source-code URI line number.
00066    * @param column The source-code URI column number.
00067    * @param line_end The source-code URI end line number.
00068    * @param column_end The source-code URI end column number.
00069    */
00070   void set_source(
00071       char const *uri,
00072       line_type line,
00073       column_type column = 0,
00074       line_type line_end = 0,
00075       column_type column_end = 0 );
00076 
00077   /**
00078    * Checks whether the XQuery source location has been set.
00079    *
00080    * @return Returns \c true only if the source location has been set.
00081    */
00082   bool has_source() const throw() {
00083     return source_loc_;
00084   }
00085 
00086   /**
00087    * Gets the XQuery source URI containing the error.
00088    *
00089    * @return Returns said URI or the empty string if unset.
00090    */
00091   char const* source_uri() const throw() {
00092     return source_loc_.file();
00093   }
00094 
00095   /**
00096    * Gets the XQuery source-code line number containing the error.
00097    *
00098    * @return Returns said line number or 0 if unset.
00099    */
00100   line_type source_line() const throw() {
00101     return source_loc_.line();
00102   }
00103 
00104   /**
00105    * Gets the XQuery source-code column number containing the error.
00106    *
00107    * @return Returns said column number or 0 if unset.
00108    */
00109   column_type source_column() const throw() {
00110     return source_loc_.column();
00111   }
00112 
00113   /**
00114    * Gets the XQuery source-code end line number containing the error.
00115    *
00116    * @return Returns said line number or 0 if unset.
00117    */
00118   line_type source_line_end() const throw() {
00119     return source_loc_.line_end();
00120   }
00121 
00122   /**
00123    * Gets the XQuery source-code end column number containing the error.
00124    *
00125    * @return Returns said column number or 0 if unset.
00126    */
00127   column_type source_column_end() const throw() {
00128     return source_loc_.column_end();
00129   }
00130 
00131   /**
00132    * Gets the XQuery stack trace, if any.
00133    *
00134    * @return Returns said stack trace.
00135    */
00136   XQueryStackTrace& query_trace() throw() {
00137     return query_trace_;
00138   }
00139 
00140   /**
00141    * Gets the XQuery stack trace, if any.
00142    *
00143    * @return Returns said stack trace.
00144    */
00145   XQueryStackTrace const& query_trace() const throw() {
00146     return query_trace_;
00147   }
00148 
00149   // inherited
00150   void polymorphic_throw() const;
00151 
00152 protected:
00153   // inherited
00154   std::unique_ptr<ZorbaException> clone() const;
00155   std::ostream& print( std::ostream &o ) const;
00156 
00157 private:
00158   /**
00159    * Constructs an %XQueryException.
00160    *
00161    * @param diagnostic The diagnostic.
00162    * @param raise_file The C++ source-code file name whence the exception was
00163    * raised.
00164    * @param raise_line The C++ source-code line number whence the exception was
00165    * raised.
00166    * @param message The diagnostic message.
00167    */
00168   XQueryException( Diagnostic const &diagnostic, char const *raise_file,
00169                    line_type raise_line, char const *message );
00170 
00171   internal::diagnostic::location source_loc_;
00172   XQueryStackTrace query_trace_;
00173 
00174   friend XQueryException make_xquery_exception(
00175     char const*, ZorbaException::line_type, Diagnostic const&,
00176     internal::diagnostic::parameters const&,
00177     internal::diagnostic::location const&
00178   );
00179 
00180   friend XQueryException* new_xquery_exception(
00181     char const*, ZorbaException::line_type, Diagnostic const&,
00182     internal::diagnostic::parameters const&,
00183     internal::diagnostic::location const&
00184   );
00185 
00186   friend void set_source( ZorbaException&, char const*, line_type, column_type,
00187                           line_type, column_type, bool );
00188 
00189   friend class UserException;
00190 
00191 protected:
00192   // for plan serialization
00193   XQueryException( serialization::Archiver &ar );
00194   friend void serialization::operator&( serialization::Archiver&,
00195                                         ZorbaException*& );
00196 };
00197 
00198 ///////////////////////////////////////////////////////////////////////////////
00199 
00200 } // namespace zorba
00201 #endif /* ZORBA_XQUERY_EXCEPTION_API_H */
00202 /* vim:set et sw=2 ts=2: */
blog comments powered by Disqus