libpqxx
except.hxx
1 
13 #ifndef PQXX_H_EXCEPT
14 #define PQXX_H_EXCEPT
15 
16 #include "pqxx/compiler-public.hxx"
17 #include "pqxx/compiler-internal-pre.hxx"
18 
19 #include <stdexcept>
20 
21 #include "pqxx/util.hxx"
22 
23 
24 namespace pqxx
25 {
26 
43 
55 class PQXX_LIBEXPORT PQXX_NOVTABLE pqxx_exception
56 {
57 public:
59  virtual ~pqxx_exception() noexcept =0;
60 
62 
84  PQXX_CONST virtual const std::exception &base() const noexcept =0; //[t00]
85 };
86 
87 
89 class PQXX_LIBEXPORT failure :
90  public pqxx_exception, public std::runtime_error
91 {
92  virtual const std::exception &base() const noexcept override
93  { return *this; }
94 public:
95  explicit failure(const std::string &);
96 };
97 
98 
100 
118 class PQXX_LIBEXPORT broken_connection : public failure
119 {
120 public:
122  explicit broken_connection(const std::string &);
123 };
124 
125 
127 
130 class PQXX_LIBEXPORT sql_error : public failure
131 {
133  const std::string m_query;
135  const std::string m_sqlstate;
136 
137 public:
138  explicit sql_error(
139  const std::string &msg="",
140  const std::string &Q="",
141  const char sqlstate[]=nullptr);
142  virtual ~sql_error() noexcept;
143 
145  PQXX_PURE const std::string &query() const noexcept; //[t56]
146  PQXX_PURE const std::string &sqlstate() const noexcept;
147 };
148 
149 
151 
157 class PQXX_LIBEXPORT in_doubt_error : public failure
158 {
159 public:
160  explicit in_doubt_error(const std::string &);
161 };
162 
163 
165 class PQXX_LIBEXPORT transaction_rollback : public failure
166 {
167 public:
168  explicit transaction_rollback(const std::string &);
169 };
170 
171 
173 
181 class PQXX_LIBEXPORT serialization_failure : public transaction_rollback
182 {
183 public:
184  explicit serialization_failure(const std::string &);
185 };
186 
187 
190 {
191 public:
192  explicit statement_completion_unknown(const std::string &);
193 };
194 
195 
197 class PQXX_LIBEXPORT deadlock_detected : public transaction_rollback
198 {
199 public:
200  explicit deadlock_detected(const std::string &);
201 };
202 
203 
205 class PQXX_LIBEXPORT internal_error :
206  public pqxx_exception, public std::logic_error
207 {
208  virtual const std::exception &base() const noexcept override
209  { return *this; }
210 public:
211  explicit internal_error(const std::string &);
212 };
213 
214 
216 class PQXX_LIBEXPORT usage_error :
217  public pqxx_exception, public std::logic_error
218 {
219  virtual const std::exception &base() const noexcept override
220  { return *this; }
221 public:
222  explicit usage_error(const std::string &);
223 };
224 
225 
227 class PQXX_LIBEXPORT argument_error :
228  public pqxx_exception, public std::invalid_argument
229 {
230  virtual const std::exception &base() const noexcept override
231  { return *this; }
232 public:
233  explicit argument_error(const std::string &);
234 };
235 
236 
238 class PQXX_LIBEXPORT conversion_error :
239  public pqxx_exception, public std::domain_error
240 {
241  virtual const std::exception &base() const noexcept override
242  { return *this; }
243 public:
244  explicit conversion_error(const std::string &);
245 };
246 
247 
249 class PQXX_LIBEXPORT range_error :
250  public pqxx_exception, public std::out_of_range
251 {
252  virtual const std::exception &base() const noexcept override
253  { return *this; }
254 public:
255  explicit range_error(const std::string &);
256 };
257 
258 
260 class PQXX_LIBEXPORT unexpected_rows : public range_error
261 {
262  virtual const std::exception &base() const noexcept override
263  { return *this; }
264 public:
265  explicit unexpected_rows(const std::string &msg) : range_error(msg) {}
266 };
267 
268 
270 class PQXX_LIBEXPORT feature_not_supported : public sql_error
271 {
272 public:
274  const std::string &err,
275  const std::string &Q="",
276  const char sqlstate[]=nullptr) :
277  sql_error(err, Q, sqlstate) {}
278 };
279 
281 class PQXX_LIBEXPORT data_exception : public sql_error
282 {
283 public:
284  explicit data_exception(
285  const std::string &err,
286  const std::string &Q="",
287  const char sqlstate[]=nullptr) :
288  sql_error(err, Q, sqlstate) {}
289 };
290 
291 class PQXX_LIBEXPORT integrity_constraint_violation : public sql_error
292 {
293 public:
295  const std::string &err,
296  const std::string &Q="",
297  const char sqlstate[]=nullptr) :
298  sql_error(err, Q, sqlstate) {}
299 };
300 
301 class PQXX_LIBEXPORT restrict_violation :
303 {
304 public:
306  const std::string &err,
307  const std::string &Q="",
308  const char sqlstate[]=nullptr) :
309  integrity_constraint_violation(err, Q, sqlstate) {}
310 };
311 
312 class PQXX_LIBEXPORT not_null_violation :
314 {
315 public:
317  const std::string &err,
318  const std::string &Q="",
319  const char sqlstate[]=nullptr) :
320  integrity_constraint_violation(err, Q, sqlstate) {}
321 };
322 
323 class PQXX_LIBEXPORT foreign_key_violation :
325 {
326 public:
328  const std::string &err,
329  const std::string &Q="",
330  const char sqlstate[]=nullptr) :
331  integrity_constraint_violation(err, Q, sqlstate) {}
332 };
333 
334 class PQXX_LIBEXPORT unique_violation :
336 {
337 public:
339  const std::string &err,
340  const std::string &Q="",
341  const char sqlstate[]=nullptr) :
342  integrity_constraint_violation(err, Q, sqlstate) {}
343 };
344 
345 class PQXX_LIBEXPORT check_violation :
347 {
348 public:
349  explicit check_violation(
350  const std::string &err,
351  const std::string &Q="",
352  const char sqlstate[]=nullptr) :
353  integrity_constraint_violation(err, Q, sqlstate) {}
354 };
355 
356 class PQXX_LIBEXPORT invalid_cursor_state : public sql_error
357 {
358 public:
360  const std::string &err,
361  const std::string &Q="",
362  const char sqlstate[]=nullptr) :
363  sql_error(err, Q, sqlstate) {}
364 };
365 
366 class PQXX_LIBEXPORT invalid_sql_statement_name : public sql_error
367 {
368 public:
370  const std::string &err,
371  const std::string &Q="",
372  const char sqlstate[]=nullptr) :
373  sql_error(err, Q, sqlstate) {}
374 };
375 
376 class PQXX_LIBEXPORT invalid_cursor_name : public sql_error
377 {
378 public:
380  const std::string &err,
381  const std::string &Q="",
382  const char sqlstate[]=nullptr) :
383  sql_error(err, Q, sqlstate) {}
384 };
385 
386 class PQXX_LIBEXPORT syntax_error : public sql_error
387 {
388 public:
390  const int error_position;
391 
392  explicit syntax_error(
393  const std::string &err,
394  const std::string &Q="",
395  const char sqlstate[]=nullptr,
396  int pos=-1) :
397  sql_error(err, Q, sqlstate), error_position(pos) {}
398 };
399 
400 class PQXX_LIBEXPORT undefined_column : public syntax_error
401 {
402 public:
404  const std::string &err,
405  const std::string &Q="",
406  const char sqlstate[]=nullptr) :
407  syntax_error(err, Q, sqlstate) {}
408 };
409 
410 class PQXX_LIBEXPORT undefined_function : public syntax_error
411 {
412 public:
414  const std::string &err,
415  const std::string &Q="",
416  const char sqlstate[]=nullptr) :
417  syntax_error(err, Q, sqlstate) {}
418 };
419 
420 class PQXX_LIBEXPORT undefined_table : public syntax_error
421 {
422 public:
423  explicit undefined_table(
424  const std::string &err,
425  const std::string &Q="",
426  const char sqlstate[]=nullptr) :
427  syntax_error(err, Q, sqlstate) {}
428 };
429 
430 class PQXX_LIBEXPORT insufficient_privilege : public sql_error
431 {
432 public:
434  const std::string &err,
435  const std::string &Q="",
436  const char sqlstate[]=nullptr) :
437  sql_error(err, Q, sqlstate) {}
438 };
439 
441 class PQXX_LIBEXPORT insufficient_resources : public sql_error
442 {
443 public:
445  const std::string &err,
446  const std::string &Q="",
447  const char sqlstate[]=nullptr) :
448  sql_error(err,Q, sqlstate) {}
449 };
450 
451 class PQXX_LIBEXPORT disk_full : public insufficient_resources
452 {
453 public:
454  explicit disk_full(
455  const std::string &err,
456  const std::string &Q="",
457  const char sqlstate[]=nullptr) :
458  insufficient_resources(err, Q, sqlstate) {}
459 };
460 
461 class PQXX_LIBEXPORT out_of_memory : public insufficient_resources
462 {
463 public:
464  explicit out_of_memory(
465  const std::string &err,
466  const std::string &Q="",
467  const char sqlstate[]=nullptr) :
468  insufficient_resources(err, Q, sqlstate) {}
469 };
470 
471 class PQXX_LIBEXPORT too_many_connections : public broken_connection
472 {
473 public:
474  explicit too_many_connections(const std::string &err) :
475  broken_connection(err) {}
476 };
477 
479 
481 class PQXX_LIBEXPORT plpgsql_error : public sql_error
482 {
483 public:
484  explicit plpgsql_error(
485  const std::string &err,
486  const std::string &Q="",
487  const char sqlstate[]=nullptr) :
488  sql_error(err, Q, sqlstate) {}
489 };
490 
492 class PQXX_LIBEXPORT plpgsql_raise : public plpgsql_error
493 {
494 public:
495  explicit plpgsql_raise(
496  const std::string &err,
497  const std::string &Q="",
498  const char sqlstate[]=nullptr) :
499  plpgsql_error(err, Q, sqlstate) {}
500 };
501 
502 class PQXX_LIBEXPORT plpgsql_no_data_found : public plpgsql_error
503 {
504 public:
506  const std::string &err,
507  const std::string &Q="",
508  const char sqlstate[]=nullptr) :
509  plpgsql_error(err, Q, sqlstate) {}
510 };
511 
512 class PQXX_LIBEXPORT plpgsql_too_many_rows : public plpgsql_error
513 {
514 public:
516  const std::string &err,
517  const std::string &Q="",
518  const char sqlstate[]=nullptr) :
519  plpgsql_error(err, Q, sqlstate) {}
520 };
521 
526 }
527 
528 #include "pqxx/compiler-internal-post.hxx"
529 
530 #endif
data_exception(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:284
Invalid argument passed to libpqxx, similar to std::invalid_argument.
Definition: except.hxx:227
Resource shortage on the server.
Definition: except.hxx:441
The ongoing transaction has deadlocked. Retrying it may help.
Definition: except.hxx:197
undefined_column(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:403
plpgsql_raise(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:495
Error in data provided to SQL statement.
Definition: except.hxx:281
const int error_position
Approximate position in string where error occurred, or -1 if unknown.
Definition: except.hxx:390
Exception raised in PL/pgSQL procedure.
Definition: except.hxx:492
Something is out of range, similar to std::out_of_range.
Definition: except.hxx:249
Definition: except.hxx:461
plpgsql_too_many_rows(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:515
Definition: except.hxx:334
Definition: except.hxx:301
Definition: except.hxx:512
insufficient_privilege(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:433
unexpected_rows(const std::string &msg)
Definition: except.hxx:265
Run-time failure encountered by libpqxx, similar to std::runtime_error.
Definition: except.hxx:89
Definition: except.hxx:386
Error in usage of libpqxx library, similar to std::logic_error.
Definition: except.hxx:216
Definition: except.hxx:356
We can&#39;t tell whether our last statement succeeded.
Definition: except.hxx:189
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:22
Database feature not supported in current setup.
Definition: except.hxx:270
Exception class for failed queries.
Definition: except.hxx:130
PL/pgSQL error.
Definition: except.hxx:481
Definition: except.hxx:410
Value conversion failed, e.g. when converting "Hello" to int.
Definition: except.hxx:238
Definition: except.hxx:451
not_null_violation(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:316
Internal error in libpqxx library.
Definition: except.hxx:205
invalid_cursor_state(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:359
Definition: except.hxx:323
Definition: except.hxx:291
check_violation(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:349
Definition: except.hxx:502
out_of_memory(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:464
Query returned an unexpected number of rows.
Definition: except.hxx:260
disk_full(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:454
Definition: except.hxx:471
insufficient_resources(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:444
Mixin base class to identify libpqxx-specific exception types.
Definition: except.hxx:55
Definition: except.hxx:376
Definition: except.hxx:345
Definition: except.hxx:312
invalid_cursor_name(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:379
The backend saw itself forced to roll back the ongoing transaction.
Definition: except.hxx:165
feature_not_supported(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:273
Definition: except.hxx:430
Exception class for lost or failed backend connection.
Definition: except.hxx:118
Definition: except.hxx:400
foreign_key_violation(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:327
Definition: except.hxx:366
undefined_table(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:423
undefined_function(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:413
plpgsql_error(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:484
"Help, I don&#39;t know whether transaction was committed successfully!"
Definition: except.hxx:157
Definition: except.hxx:420
too_many_connections(const std::string &err)
Definition: except.hxx:474
restrict_violation(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:305
syntax_error(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr, int pos=-1)
Definition: except.hxx:392
Transaction failed to serialize. Please retry it.
Definition: except.hxx:181
plpgsql_no_data_found(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:505
invalid_sql_statement_name(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:369
unique_violation(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:338
integrity_constraint_violation(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:294