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