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  /**
62  * Sets the XQuery source-code URI name, line, and column numbers.
63  *
64  * @param uri The source-code URI name.
65  * @param line The source-code URI line number.
66  * @param column The source-code URI column number.
67  * @param line_end The source-code URI end line number.
68  * @param column_end The source-code URI end column number.
69  */
70  void set_source(
71  char const *uri,
72  line_type line,
73  column_type column = 0,
74  line_type line_end = 0,
75  column_type column_end = 0 );
76 
77  /**
78  * Checks whether the XQuery source location has been set.
79  *
80  * @return Returns \c true only if the source location has been set.
81  */
82  bool has_source() const throw() {
83  return source_loc_;
84  }
85 
86  /**
87  * Gets the XQuery source URI containing the error.
88  *
89  * @return Returns said URI or the empty string if unset.
90  */
91  char const* source_uri() const throw() {
92  return source_loc_.file();
93  }
94 
95  /**
96  * Gets the XQuery source-code line number containing the error.
97  *
98  * @return Returns said line number or 0 if unset.
99  */
100  line_type source_line() const throw() {
101  return source_loc_.line();
102  }
103 
104  /**
105  * Gets the XQuery source-code column number containing the error.
106  *
107  * @return Returns said column number or 0 if unset.
108  */
109  column_type source_column() const throw() {
110  return source_loc_.column();
111  }
112 
113  /**
114  * Gets the XQuery source-code end line number containing the error.
115  *
116  * @return Returns said line number or 0 if unset.
117  */
118  line_type source_line_end() const throw() {
119  return source_loc_.line_end();
120  }
121 
122  /**
123  * Gets the XQuery source-code end column number containing the error.
124  *
125  * @return Returns said column number or 0 if unset.
126  */
127  column_type source_column_end() const throw() {
128  return source_loc_.column_end();
129  }
130 
131  /**
132  * Gets the XQuery stack trace, if any.
133  *
134  * @return Returns said stack trace.
135  */
137  return query_trace_;
138  }
139 
140  /**
141  * Gets the XQuery stack trace, if any.
142  *
143  * @return Returns said stack trace.
144  */
145  XQueryStackTrace const& query_trace() const throw() {
146  return query_trace_;
147  }
148 
149  // inherited
150  void polymorphic_throw() const;
151 
152 protected:
153  // inherited
154  std::unique_ptr<ZorbaException> clone() const;
155  std::ostream& print( std::ostream &o ) const;
156 
157 private:
158  /**
159  * Constructs an %XQueryException.
160  *
161  * @param diagnostic The diagnostic.
162  * @param raise_file The C++ source-code file name whence the exception was
163  * raised.
164  * @param raise_line The C++ source-code line number whence the exception was
165  * raised.
166  * @param message The diagnostic message.
167  */
168  XQueryException( Diagnostic const &diagnostic, char const *raise_file,
169  line_type raise_line, char const *message );
170 
171  internal::diagnostic::location source_loc_;
172  XQueryStackTrace query_trace_;
173 
174  friend XQueryException make_xquery_exception(
175  char const*, ZorbaException::line_type, Diagnostic const&,
178  );
179 
180  friend XQueryException* new_xquery_exception(
181  char const*, ZorbaException::line_type, Diagnostic const&,
184  );
185 
186  friend void set_source( ZorbaException&, char const*, line_type, column_type,
187  line_type, column_type, bool );
188 
189  friend class UserException;
190 
191 protected:
192  // for plan serialization
193  XQueryException( serialization::Archiver &ar );
194  friend void serialization::operator&( serialization::Archiver&,
195  ZorbaException*& );
196 };
197 
198 ///////////////////////////////////////////////////////////////////////////////
199 
200 } // namespace zorba
201 #endif /* ZORBA_XQUERY_EXCEPTION_API_H */
202 /* vim:set et sw=2 ts=2: */
blog comments powered by Disqus