libpqxx  7.1.2
except.hxx
1 /* Definition of libpqxx exception classes.
2  *
3  * pqxx::sql_error, pqxx::broken_connection, pqxx::in_doubt_error, ...
4  *
5  * DO NOT INCLUDE THIS FILE DIRECTLY; include pqxx/except instead.
6  *
7  * Copyright (c) 2000-2020, Jeroen T. Vermeulen.
8  *
9  * See COPYING for copyright license. If you did not receive a file called
10  * COPYING with this source code, please notify the distributor of this
11  * mistake, or contact the author.
12  */
13 #ifndef PQXX_H_EXCEPT
14 #define PQXX_H_EXCEPT
15 
16 #include "pqxx/compiler-public.hxx"
17 #include "pqxx/internal/compiler-internal-pre.hxx"
18 
19 #include <stdexcept>
20 #include <string>
21 
22 
23 // TODO: Move vtable to except.cxx, by implementing destructors there.
24 namespace pqxx
25 {
42 struct PQXX_LIBEXPORT failure : std::runtime_error
44 {
45  explicit failure(std::string const &);
46 };
47 
48 
50 
68 struct PQXX_LIBEXPORT broken_connection : failure
69 {
71  explicit broken_connection(std::string const &);
72 };
73 
74 
76 
79 class PQXX_LIBEXPORT sql_error : public failure
80 {
82  std::string const m_query;
84  std::string const m_sqlstate;
85 
86 public:
87  explicit sql_error(
88  std::string const &whatarg = "", std::string const &Q = "",
89  char const sqlstate[] = nullptr);
90  virtual ~sql_error() noexcept override;
91 
93  [[nodiscard]] PQXX_PURE std::string const &query() const noexcept;
94 
96  [[nodiscard]] PQXX_PURE std::string const &sqlstate() const noexcept;
97 };
98 
99 
101 
107 struct PQXX_LIBEXPORT in_doubt_error : failure
108 {
109  explicit in_doubt_error(std::string const &);
110 };
111 
112 
114 struct PQXX_LIBEXPORT transaction_rollback : sql_error
115 {
116  explicit transaction_rollback(
117  std::string const &whatarg, std::string const &q = "",
118  char const sqlstate[] = nullptr);
119 };
120 
121 
123 
132 {
133  explicit serialization_failure(
134  std::string const &whatarg, std::string const &q,
135  char const sqlstate[] = nullptr);
136 };
137 
138 
141 {
143  std::string const &whatarg, std::string const &q,
144  char const sqlstate[] = nullptr);
145 };
146 
147 
150 {
151  explicit deadlock_detected(
152  std::string const &whatarg, std::string const &q,
153  char const sqlstate[] = nullptr);
154 };
155 
156 
158 struct PQXX_LIBEXPORT internal_error : std::logic_error
159 {
160  explicit internal_error(std::string const &);
161 };
162 
163 
165 struct PQXX_LIBEXPORT usage_error : std::logic_error
166 {
167  explicit usage_error(std::string const &);
168 };
169 
170 
172 struct PQXX_LIBEXPORT argument_error : std::invalid_argument
173 {
174  explicit argument_error(std::string const &);
175 };
176 
177 
179 struct PQXX_LIBEXPORT conversion_error : std::domain_error
180 {
181  explicit conversion_error(std::string const &);
182 };
183 
184 
186 struct PQXX_LIBEXPORT conversion_overrun : conversion_error
187 {
188  explicit conversion_overrun(std::string const &);
189 };
190 
191 
193 struct PQXX_LIBEXPORT range_error : std::out_of_range
194 {
195  explicit range_error(std::string const &);
196 };
197 
198 
200 struct PQXX_LIBEXPORT unexpected_rows : public range_error
201 {
202  explicit unexpected_rows(std::string const &msg) : range_error{msg} {}
203 };
204 
205 
207 struct PQXX_LIBEXPORT feature_not_supported : sql_error
208 {
210  std::string const &err, std::string const &Q = "",
211  char const sqlstate[] = nullptr) :
212  sql_error{err, Q, sqlstate}
213  {}
214 };
215 
217 struct PQXX_LIBEXPORT data_exception : sql_error
218 {
219  explicit data_exception(
220  std::string const &err, std::string const &Q = "",
221  char const sqlstate[] = nullptr) :
222  sql_error{err, Q, sqlstate}
223  {}
224 };
225 
227 {
229  std::string const &err, std::string const &Q = "",
230  char const sqlstate[] = nullptr) :
231  sql_error{err, Q, sqlstate}
232  {}
233 };
234 
236 {
238  std::string const &err, std::string const &Q = "",
239  char const sqlstate[] = nullptr) :
240  integrity_constraint_violation{err, Q, sqlstate}
241  {}
242 };
243 
245 {
247  std::string const &err, std::string const &Q = "",
248  char const sqlstate[] = nullptr) :
249  integrity_constraint_violation{err, Q, sqlstate}
250  {}
251 };
252 
254 {
256  std::string const &err, std::string const &Q = "",
257  char const sqlstate[] = nullptr) :
258  integrity_constraint_violation{err, Q, sqlstate}
259  {}
260 };
261 
263 {
265  std::string const &err, std::string const &Q = "",
266  char const sqlstate[] = nullptr) :
267  integrity_constraint_violation{err, Q, sqlstate}
268  {}
269 };
270 
272 {
273  explicit check_violation(
274  std::string const &err, std::string const &Q = "",
275  char const sqlstate[] = nullptr) :
276  integrity_constraint_violation{err, Q, sqlstate}
277  {}
278 };
279 
280 struct PQXX_LIBEXPORT invalid_cursor_state : sql_error
281 {
283  std::string const &err, std::string const &Q = "",
284  char const sqlstate[] = nullptr) :
285  sql_error{err, Q, sqlstate}
286  {}
287 };
288 
289 struct PQXX_LIBEXPORT invalid_sql_statement_name : sql_error
290 {
292  std::string const &err, std::string const &Q = "",
293  char const sqlstate[] = nullptr) :
294  sql_error{err, Q, sqlstate}
295  {}
296 };
297 
298 struct PQXX_LIBEXPORT invalid_cursor_name : sql_error
299 {
301  std::string const &err, std::string const &Q = "",
302  char const sqlstate[] = nullptr) :
303  sql_error{err, Q, sqlstate}
304  {}
305 };
306 
307 struct PQXX_LIBEXPORT syntax_error : sql_error
308 {
310  int const error_position;
311 
312  explicit syntax_error(
313  std::string const &err, std::string const &Q = "",
314  char const sqlstate[] = nullptr, int pos = -1) :
315  sql_error{err, Q, sqlstate}, error_position{pos}
316  {}
317 };
318 
319 struct PQXX_LIBEXPORT undefined_column : syntax_error
320 {
322  std::string const &err, std::string const &Q = "",
323  char const sqlstate[] = nullptr) :
324  syntax_error{err, Q, sqlstate}
325  {}
326 };
327 
328 struct PQXX_LIBEXPORT undefined_function : syntax_error
329 {
331  std::string const &err, std::string const &Q = "",
332  char const sqlstate[] = nullptr) :
333  syntax_error{err, Q, sqlstate}
334  {}
335 };
336 
337 struct PQXX_LIBEXPORT undefined_table : syntax_error
338 {
339  explicit undefined_table(
340  std::string const &err, std::string const &Q = "",
341  char const sqlstate[] = nullptr) :
342  syntax_error{err, Q, sqlstate}
343  {}
344 };
345 
346 struct PQXX_LIBEXPORT insufficient_privilege : sql_error
347 {
349  std::string const &err, std::string const &Q = "",
350  char const sqlstate[] = nullptr) :
351  sql_error{err, Q, sqlstate}
352  {}
353 };
354 
356 struct PQXX_LIBEXPORT insufficient_resources : sql_error
357 {
359  std::string const &err, std::string const &Q = "",
360  char const sqlstate[] = nullptr) :
361  sql_error{err, Q, sqlstate}
362  {}
363 };
364 
365 struct PQXX_LIBEXPORT disk_full : insufficient_resources
366 {
367  explicit disk_full(
368  std::string const &err, std::string const &Q = "",
369  char const sqlstate[] = nullptr) :
370  insufficient_resources{err, Q, sqlstate}
371  {}
372 };
373 
374 struct PQXX_LIBEXPORT out_of_memory : insufficient_resources
375 {
376  explicit out_of_memory(
377  std::string const &err, std::string const &Q = "",
378  char const sqlstate[] = nullptr) :
379  insufficient_resources{err, Q, sqlstate}
380  {}
381 };
382 
384 {
385  explicit too_many_connections(std::string const &err) :
386  broken_connection{err}
387  {}
388 };
389 
391 
393 struct PQXX_LIBEXPORT plpgsql_error : sql_error
394 {
395  explicit plpgsql_error(
396  std::string const &err, std::string const &Q = "",
397  char const sqlstate[] = nullptr) :
398  sql_error{err, Q, sqlstate}
399  {}
400 };
401 
403 struct PQXX_LIBEXPORT plpgsql_raise : plpgsql_error
404 {
405  explicit plpgsql_raise(
406  std::string const &err, std::string const &Q = "",
407  char const sqlstate[] = nullptr) :
408  plpgsql_error{err, Q, sqlstate}
409  {}
410 };
411 
412 struct PQXX_LIBEXPORT plpgsql_no_data_found : plpgsql_error
413 {
415  std::string const &err, std::string const &Q = "",
416  char const sqlstate[] = nullptr) :
417  plpgsql_error{err, Q, sqlstate}
418  {}
419 };
420 
421 struct PQXX_LIBEXPORT plpgsql_too_many_rows : plpgsql_error
422 {
424  std::string const &err, std::string const &Q = "",
425  char const sqlstate[] = nullptr) :
426  plpgsql_error{err, Q, sqlstate}
427  {}
428 };
429 
433 } // namespace pqxx
434 
435 #include "pqxx/internal/compiler-internal-post.hxx"
436 #endif
undefined_table(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:339
plpgsql_error(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:395
insufficient_resources(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:358
Something is out of range, similar to std::out_of_range.
Definition: except.hxx:193
Definition: except.hxx:421
Database feature not supported in current setup.
Definition: except.hxx:207
check_violation(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:273
Definition: except.hxx:253
syntax_error(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr, int pos=-1)
Definition: except.hxx:312
invalid_cursor_state(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:282
Run-time failure encountered by libpqxx, similar to std::runtime_error.
Definition: except.hxx:43
Definition: except.hxx:298
foreign_key_violation(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:255
undefined_column(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:321
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:25
Definition: except.hxx:226
Transaction failed to serialize. Please retry it.
Definition: except.hxx:131
Definition: except.hxx:346
int const error_position
Approximate position in string where error occurred, or -1 if unknown.
Definition: except.hxx:310
Definition: except.hxx:271
Invalid argument passed to libpqxx, similar to std::invalid_argument.
Definition: except.hxx:172
PL/pgSQL error.
Definition: except.hxx:393
Definition: except.hxx:244
Error in data provided to SQL statement.
Definition: except.hxx:217
data_exception(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:219
invalid_cursor_name(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:300
Exception class for failed queries.
Definition: except.hxx:79
Definition: except.hxx:319
Definition: except.hxx:289
Definition: except.hxx:262
disk_full(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:367
Definition: except.hxx:235
not_null_violation(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:246
The ongoing transaction has deadlocked. Retrying it may help.
Definition: except.hxx:149
plpgsql_raise(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:405
Definition: except.hxx:365
restrict_violation(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:237
The backend saw itself forced to roll back the ongoing transaction.
Definition: except.hxx:114
Definition: except.hxx:337
invalid_sql_statement_name(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:291
Exception class for lost or failed backend connection.
Definition: except.hxx:68
Definition: except.hxx:307
Definition: except.hxx:280
plpgsql_no_data_found(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:414
Could not convert value to string: not enough buffer space.
Definition: except.hxx:186
Definition: except.hxx:412
Error in usage of libpqxx library, similar to std::logic_error.
Definition: except.hxx:165
unexpected_rows(std::string const &msg)
Definition: except.hxx:202
Definition: except.hxx:383
plpgsql_too_many_rows(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:423
integrity_constraint_violation(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:228
We can&#39;t tell whether our last statement succeeded.
Definition: except.hxx:140
Resource shortage on the server.
Definition: except.hxx:356
insufficient_privilege(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:348
"Help, I don&#39;t know whether transaction was committed successfully!"
Definition: except.hxx:107
undefined_function(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:330
Definition: except.hxx:328
Query returned an unexpected number of rows.
Definition: except.hxx:200
out_of_memory(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:376
too_many_connections(std::string const &err)
Definition: except.hxx:385
unique_violation(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:264
feature_not_supported(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:209
Value conversion failed, e.g. when converting "Hello" to int.
Definition: except.hxx:179
Exception raised in PL/pgSQL procedure.
Definition: except.hxx:403
Internal error in libpqxx library.
Definition: except.hxx:158
Definition: except.hxx:374