xquery_exception.h
Go to the documentation of this file.
1 /*
2  * Copyright 2006-2008 The FLWOR Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ZORBA_XQUERY_EXCEPTION_API_H
18 #define ZORBA_XQUERY_EXCEPTION_API_H
19 
21 #include <zorba/zorba_exception.h>
22 
23 namespace zorba {
24 
25 namespace serialization {
26  class Archiver;
27  void operator&( Archiver&, ZorbaException*& );
28 }
29 
30 ///////////////////////////////////////////////////////////////////////////////
31 
32 /**
33  * An %XQueryException is-a ZorbaException for errors with the user's XQuery.
34  * An %XQueryException therefore also contains the XQuery source URI, line, and
35  * column numbers.
36  */
37 class ZORBA_DLL_PUBLIC XQueryException : public ZorbaException {
38 public:
40 
41  /**
42  * Copy-constructs an %XQueryException.
43  *
44  * @param from The %XQueryException to copy from.
45  */
46  XQueryException( XQueryException const &from );
47 
48  /**
49  * Destroys this %XQueryException.
50  */
51  ~XQueryException() throw();
52 
53  /**
54  * Assigns this %XQueryException from another.
55  *
56  * @param from The %XQueryException to assign from.
57  * @return Returns \c *this.
58  */
59  XQueryException& operator=( XQueryException const &from );
60 
61  ////////// source file/line location ////////////////////////////////////////
62 
63  /**
64  * Checks whether the XQuery source-code location has been set.
65  *
66  * @return Returns \c true only if said has been set.
67  */
68  bool has_source() const throw() {
69  return source_loc_;
70  }
71 
72  /**
73  * Sets the XQuery source-code URI name, line, and column numbers.
74  *
75  * @param uri The source-code URI name.
76  * @param line The source-code URI line number.
77  * @param column The source-code URI column number.
78  * @param line_end The source-code URI end line number.
79  * @param column_end The source-code URI end column number.
80  */
81  void set_source( char const *uri,
82  line_type line,
83  column_type column = 0,
84  line_type line_end = 0,
85  column_type column_end = 0 );
86 
87  /**
88  * Gets the XQuery source-code URI containing the error.
89  *
90  * @return Returns said URI or the empty string if unset.
91  */
92  char const* source_uri() const throw() {
93  return source_loc_.file();
94  }
95 
96  /**
97  * Gets the XQuery source-code line number containing the error.
98  *
99  * @return Returns said line number or 0 if unset.
100  */
101  line_type source_line() const throw() {
102  return source_loc_.line();
103  }
104 
105  /**
106  * Gets the XQuery source-code column number containing the error.
107  *
108  * @return Returns said column number or 0 if unset.
109  */
110  column_type source_column() const throw() {
111  return source_loc_.column();
112  }
113 
114  /**
115  * Gets the XQuery source-code end line number containing the error.
116  *
117  * @return Returns said line number or 0 if unset.
118  */
119  line_type source_line_end() const throw() {
120  return source_loc_.line_end();
121  }
122 
123  /**
124  * Gets the XQuery source-code end column number containing the error.
125  *
126  * @return Returns said column number or 0 if unset.
127  */
128  column_type source_column_end() const throw() {
129  return source_loc_.column_end();
130  }
131 
132  ////////// "applied at" file/line location //////////////////////////////////
133 
134  /**
135  * Checks whether the XQuery "applied at" location has been set.
136  *
137  * @return Returns \c true only if the "applied at" location has been set.
138  */
139  bool has_applied() const throw() {
140  return applied_loc_;
141  }
142 
143  /**
144  * Sets the XQuery source-code "applied at" URI name, line, and column
145  * numbers.
146  *
147  * @param uri The source-code "applied at" URI name. If either the null
148  * pointer or the empty string, \c source_uri() is used.
149  * @param line The source-code "applied at" URI line number.
150  * @param column The source-code "applied at" URI column number.
151  * @param line_end The source-code "applied at" URI end line number.
152  * @param column_end The source-code "applied at" URI end column number.
153  */
154  void set_applied( char const *uri,
155  line_type line,
156  column_type column = 0,
157  line_type line_end = 0,
158  column_type column_end = 0 );
159 
160  /**
161  * Gets the XQuery source-code "applied at" URI containing the error.
162  *
163  * @return Returns said URI or the empty string if unset.
164  */
165  char const* applied_uri() const throw() {
166  return applied_loc_.file();
167  }
168 
169  /**
170  * Gets the XQuery source-code "applied at" line number containing the error.
171  *
172  * @return Returns said line number or 0 if unset.
173  */
174  line_type applied_line() const throw() {
175  return applied_loc_.line();
176  }
177 
178  /**
179  * Gets the XQuery source-code "applied at" column number containing the
180  * error.
181  *
182  * @return Returns said column number or 0 if unset.
183  */
184  column_type applied_column() const throw() {
185  return applied_loc_.column();
186  }
187 
188  /**
189  * Gets the XQuery source-code "applied at" end line number containing the
190  * error.
191  *
192  * @return Returns said line number or 0 if unset.
193  */
194  line_type applied_line_end() const throw() {
195  return applied_loc_.line_end();
196  }
197 
198  /**
199  * Gets the XQuery source-code "applied at" end column number containing the
200  * error.
201  *
202  * @return Returns said column number or 0 if unset.
203  */
204  column_type applied_column_end() const throw() {
205  return applied_loc_.column_end();
206  }
207 
208  ////////// XQuery stack trace ///////////////////////////////////////////////
209 
210  /**
211  * Gets the XQuery stack trace, if any.
212  *
213  * @return Returns said stack trace.
214  */
216  return query_trace_;
217  }
218 
219  /**
220  * Gets the XQuery stack trace, if any.
221  *
222  * @return Returns said stack trace.
223  */
224  XQueryStackTrace const& query_trace() const throw() {
225  return query_trace_;
226  }
227 
228  // inherited
229  void polymorphic_throw() const;
230 
231 protected:
232  // inherited
233  std::unique_ptr<ZorbaException> clone() const;
234  std::ostream& print( std::ostream &o ) const;
235 
236 private:
237  typedef internal::diagnostic::location location;
238  typedef internal::diagnostic::parameters parameters;
239 
240  /**
241  * Constructs an %XQueryException.
242  *
243  * @param diagnostic The diagnostic.
244  * @param raise_file The C++ source-code file name whence the exception was
245  * raised.
246  * @param raise_line The C++ source-code line number whence the exception was
247  * raised.
248  * @param message The diagnostic message.
249  */
250  XQueryException( Diagnostic const &diagnostic, char const *raise_file,
251  line_type raise_line, char const *message );
252 
253  location source_loc_;
254  location applied_loc_;
255  XQueryStackTrace query_trace_;
256 
257  friend XQueryException make_xquery_exception(
258  char const*, ZorbaException::line_type, Diagnostic const&,
259  parameters const&, location const&
260  );
261 
262  friend XQueryException* new_xquery_exception(
263  char const*, ZorbaException::line_type, Diagnostic const&,
264  parameters const&, location const&
265  );
266 
267  friend void set_applied( ZorbaException&, char const*, line_type, column_type,
268  line_type, column_type, bool );
269 
270  friend void set_source( ZorbaException&, char const*, line_type, column_type,
271  line_type, column_type, bool );
272 
273  friend class UserException;
274 
275 protected:
276  // for plan serialization
277  XQueryException( serialization::Archiver &ar );
278  friend void serialization::operator&( serialization::Archiver&,
279  ZorbaException*& );
280 };
281 
282 ///////////////////////////////////////////////////////////////////////////////
283 
284 } // namespace zorba
285 #endif /* ZORBA_XQUERY_EXCEPTION_API_H */
286 /* vim:set et sw=2 ts=2: */
blog comments powered by Disqus