libpqxx 7.8.0
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-2023, 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#if !defined(PQXX_HEADER_PRE)
17# error "Include libpqxx headers as <pqxx/header>, not <pqxx/header.hxx>."
18#endif
19
20#if pqxx_have_source_location
21#include <source_location>
22#endif
23
24#include <stdexcept>
25#include <string>
26
27
28namespace pqxx
29{
47struct PQXX_LIBEXPORT failure : std::runtime_error
48{
49#if pqxx_have_source_location
50 explicit failure(
51 std::string const &,
52 std::source_location = std::source_location::current()
53 );
54 std::source_location location;
55#else
56 explicit failure(std::string const &);
57#endif
58};
59
60
62
81struct PQXX_LIBEXPORT broken_connection : failure
82{
84 explicit broken_connection(std::string const &
85#if pqxx_have_source_location
86 , std::source_location = std::source_location::current()
87#endif
88 );
89};
90
91
93
102{
103 explicit protocol_violation(std::string const &
104#if pqxx_have_source_location
105 , std::source_location = std::source_location::current()
106#endif
107 );
108};
109
110
112struct PQXX_LIBEXPORT variable_set_to_null : failure
113{
114 explicit variable_set_to_null(
115 std::string const &
116#if pqxx_have_source_location
117 , std::source_location = std::source_location::current()
118#endif
119 );
120};
121
122
124
127class PQXX_LIBEXPORT sql_error : public failure
128{
130 std::string const m_query;
132 std::string const m_sqlstate;
133
134public:
135 explicit sql_error(
136 std::string const &whatarg = "", std::string const &Q = "",
137 char const sqlstate[] = nullptr
138#if pqxx_have_source_location
139 , std::source_location = std::source_location::current()
140#endif
141 );
142 virtual ~sql_error() noexcept override;
143
145 [[nodiscard]] PQXX_PURE std::string const &query() const noexcept;
146
148 [[nodiscard]] PQXX_PURE std::string const &sqlstate() const noexcept;
149};
150
151
153
159struct PQXX_LIBEXPORT in_doubt_error : failure
160{
161 explicit in_doubt_error(std::string const &
162#if pqxx_have_source_location
163 , std::source_location = std::source_location::current()
164#endif
165 );
166};
167
168
170struct PQXX_LIBEXPORT transaction_rollback : sql_error
171{
172 explicit transaction_rollback(
173 std::string const &whatarg, std::string const &q = "",
174 char const sqlstate[] = nullptr
175#if pqxx_have_source_location
176 , std::source_location = std::source_location::current()
177#endif
178 );
179};
180
181
183
192{
193 explicit serialization_failure(
194 std::string const &whatarg, std::string const &q,
195 char const sqlstate[] = nullptr
196#if pqxx_have_source_location
197 , std::source_location = std::source_location::current()
198#endif
199 );
200};
201
202
205{
207 std::string const &whatarg, std::string const &q,
208 char const sqlstate[] = nullptr
209#if pqxx_have_source_location
210 , std::source_location = std::source_location::current()
211#endif
212 );
213};
214
215
218{
219 explicit deadlock_detected(
220 std::string const &whatarg, std::string const &q,
221 char const sqlstate[] = nullptr
222#if pqxx_have_source_location
223 , std::source_location = std::source_location::current()
224#endif
225 );
226};
227
228
230struct PQXX_LIBEXPORT internal_error : std::logic_error
231{
232 explicit internal_error(std::string const &);
233};
234
235
237struct PQXX_LIBEXPORT usage_error : std::logic_error
238{
239 explicit usage_error(std::string const &
240#if pqxx_have_source_location
241 , std::source_location = std::source_location::current()
242#endif
243 );
244
245#if pqxx_have_source_location
246 std::source_location location;
247#endif
248};
249
250
252struct PQXX_LIBEXPORT argument_error : std::invalid_argument
253{
254 explicit argument_error(std::string const &
255#if pqxx_have_source_location
256 , std::source_location = std::source_location::current()
257#endif
258 );
259
260#if pqxx_have_source_location
261 std::source_location location;
262#endif
263};
264
265
267struct PQXX_LIBEXPORT conversion_error : std::domain_error
268{
269 explicit conversion_error(std::string const &
270#if pqxx_have_source_location
271 , std::source_location = std::source_location::current()
272#endif
273 );
274
275#if pqxx_have_source_location
276 std::source_location location;
277#endif
278};
279
280
282struct PQXX_LIBEXPORT unexpected_null : conversion_error
283{
284 explicit unexpected_null(std::string const &
285#if pqxx_have_source_location
286 , std::source_location = std::source_location::current()
287#endif
288 );
289};
290
291
294{
295 explicit conversion_overrun(std::string const &
296#if pqxx_have_source_location
297 , std::source_location = std::source_location::current()
298#endif
299 );
300};
301
302
304struct PQXX_LIBEXPORT range_error : std::out_of_range
305{
306 explicit range_error(std::string const &
307#if pqxx_have_source_location
308 , std::source_location = std::source_location::current()
309#endif
310 );
311
312#if pqxx_have_source_location
313 std::source_location location;
314#endif
315};
316
317
319struct PQXX_LIBEXPORT unexpected_rows : public range_error
320{
321#if pqxx_have_source_location
322 explicit unexpected_rows(
323 std::string const &msg,
324 std::source_location loc = std::source_location::current()
325 ) :
326 range_error{msg, loc} {}
327#else
328 explicit unexpected_rows(std::string const &msg) : range_error{msg} {}
329#endif
330};
331
332
334struct PQXX_LIBEXPORT feature_not_supported : sql_error
335{
336#if pqxx_have_source_location
337 explicit feature_not_supported(
338 std::string const &err, std::string const &Q = "",
339 char const sqlstate[] = nullptr,
340 std::source_location loc = std::source_location::current()) :
341 sql_error{err, Q, sqlstate, loc}
342 {}
343#else
345 std::string const &err, std::string const &Q = "",
346 char const sqlstate[] = nullptr) :
347 sql_error{err, Q, sqlstate}
348 {}
349#endif
350};
351
353struct PQXX_LIBEXPORT data_exception : sql_error
354{
355#if pqxx_have_source_location
356 explicit data_exception(
357 std::string const &err, std::string const &Q = "",
358 char const sqlstate[] = nullptr,
359 std::source_location loc = std::source_location::current()) :
360 sql_error{err, Q, sqlstate, loc}
361 {}
362#else
364 std::string const &err, std::string const &Q = "",
365 char const sqlstate[] = nullptr) :
366 sql_error{err, Q, sqlstate}
367 {}
368#endif
369};
370
372{
373#if pqxx_have_source_location
375 std::string const &err, std::string const &Q = "",
376 char const sqlstate[] = nullptr,
377 std::source_location loc = std::source_location::current()) :
378 sql_error{err, Q, sqlstate, loc}
379 {}
380#else
382 std::string const &err, std::string const &Q = "",
383 char const sqlstate[] = nullptr) :
384 sql_error{err, Q, sqlstate}
385 {}
386#endif
387};
388
390{
391#if pqxx_have_source_location
392 explicit restrict_violation(
393 std::string const &err, std::string const &Q = "",
394 char const sqlstate[] = nullptr,
395 std::source_location loc = std::source_location::current()) :
396 integrity_constraint_violation{err, Q, sqlstate, loc}
397 {}
398#else
400 std::string const &err, std::string const &Q = "",
401 char const sqlstate[] = nullptr) :
402 integrity_constraint_violation{err, Q, sqlstate}
403 {}
404#endif
405};
406
408{
409#if pqxx_have_source_location
410 explicit not_null_violation(
411 std::string const &err, std::string const &Q = "",
412 char const sqlstate[] = nullptr,
413 std::source_location loc = std::source_location::current()) :
414 integrity_constraint_violation{err, Q, sqlstate, loc}
415 {}
416#else
418 std::string const &err, std::string const &Q = "",
419 char const sqlstate[] = nullptr) :
420 integrity_constraint_violation{err, Q, sqlstate}
421 {}
422#endif
423};
424
426{
427#if pqxx_have_source_location
428 explicit foreign_key_violation(
429 std::string const &err, std::string const &Q = "",
430 char const sqlstate[] = nullptr,
431 std::source_location loc = std::source_location::current()) :
432 integrity_constraint_violation{err, Q, sqlstate, loc}
433 {}
434#else
436 std::string const &err, std::string const &Q = "",
437 char const sqlstate[] = nullptr) :
438 integrity_constraint_violation{err, Q, sqlstate}
439 {}
440#endif
441};
442
444{
445#if pqxx_have_source_location
446 explicit unique_violation(
447 std::string const &err, std::string const &Q = "",
448 char const sqlstate[] = nullptr,
449 std::source_location loc = std::source_location::current()) :
450 integrity_constraint_violation{err, Q, sqlstate, loc}
451 {}
452#else
454 std::string const &err, std::string const &Q = "",
455 char const sqlstate[] = nullptr) :
456 integrity_constraint_violation{err, Q, sqlstate}
457 {}
458#endif
459};
460
462{
463#if pqxx_have_source_location
464 explicit check_violation(
465 std::string const &err, std::string const &Q = "",
466 char const sqlstate[] = nullptr,
467 std::source_location loc = std::source_location::current()) :
468 integrity_constraint_violation{err, Q, sqlstate, loc}
469 {}
470#else
472 std::string const &err, std::string const &Q = "",
473 char const sqlstate[] = nullptr) :
474 integrity_constraint_violation{err, Q, sqlstate}
475 {}
476#endif
477};
478
479struct PQXX_LIBEXPORT invalid_cursor_state : sql_error
480{
481#if pqxx_have_source_location
482 explicit invalid_cursor_state(
483 std::string const &err, std::string const &Q = "",
484 char const sqlstate[] = nullptr,
485 std::source_location loc = std::source_location::current()) :
486 sql_error{err, Q, sqlstate, loc}
487 {}
488#else
490 std::string const &err, std::string const &Q = "",
491 char const sqlstate[] = nullptr) :
492 sql_error{err, Q, sqlstate}
493 {}
494#endif
495};
496
498{
499#if pqxx_have_source_location
501 std::string const &err, std::string const &Q = "",
502 char const sqlstate[] = nullptr,
503 std::source_location loc = std::source_location::current()) :
504 sql_error{err, Q, sqlstate, loc}
505 {}
506#else
508 std::string const &err, std::string const &Q = "",
509 char const sqlstate[] = nullptr) :
510 sql_error{err, Q, sqlstate}
511 {}
512#endif
513};
514
515struct PQXX_LIBEXPORT invalid_cursor_name : sql_error
516{
517#if pqxx_have_source_location
518 explicit invalid_cursor_name(
519 std::string const &err, std::string const &Q = "",
520 char const sqlstate[] = nullptr,
521 std::source_location loc = std::source_location::current()) :
522 sql_error{err, Q, sqlstate, loc}
523 {}
524#else
526 std::string const &err, std::string const &Q = "",
527 char const sqlstate[] = nullptr) :
528 sql_error{err, Q, sqlstate}
529 {}
530#endif
531};
532
533struct PQXX_LIBEXPORT syntax_error : sql_error
534{
536 int const error_position;
537
538#if pqxx_have_source_location
539 explicit syntax_error(
540 std::string const &err, std::string const &Q = "",
541 char const sqlstate[] = nullptr, int pos = -1,
542 std::source_location loc = std::source_location::current()) :
543 sql_error{err, Q, sqlstate, loc}, error_position{pos}
544 {}
545#else
546 explicit syntax_error(
547 std::string const &err, std::string const &Q = "",
548 char const sqlstate[] = nullptr, int pos = -1) :
549 sql_error{err, Q, sqlstate}, error_position{pos}
550 {}
551#endif
552};
553
554struct PQXX_LIBEXPORT undefined_column : syntax_error
555{
556#if pqxx_have_source_location
557 explicit undefined_column(
558 std::string const &err, std::string const &Q = "",
559 char const sqlstate[] = nullptr,
560 std::source_location loc = std::source_location::current()) :
561// TODO: Can we get the column?
562 syntax_error{err, Q, sqlstate, -1, loc}
563 {}
564#else
566 std::string const &err, std::string const &Q = "",
567 char const sqlstate[] = nullptr) :
568 syntax_error{err, Q, sqlstate}
569 {}
570#endif
571};
572
573struct PQXX_LIBEXPORT undefined_function : syntax_error
574{
575#if pqxx_have_source_location
576 explicit undefined_function(
577 std::string const &err, std::string const &Q = "",
578 char const sqlstate[] = nullptr,
579 std::source_location loc = std::source_location::current()) :
580// TODO: Can we get the column?
581 syntax_error{err, Q, sqlstate, -1, loc}
582 {}
583#else
585 std::string const &err, std::string const &Q = "",
586 char const sqlstate[] = nullptr) :
587 syntax_error{err, Q, sqlstate}
588 {}
589#endif
590};
591
592struct PQXX_LIBEXPORT undefined_table : syntax_error
593{
594#if pqxx_have_source_location
595 explicit undefined_table(
596 std::string const &err, std::string const &Q = "",
597 char const sqlstate[] = nullptr,
598 std::source_location loc = std::source_location::current()) :
599// TODO: Can we get the column?
600 syntax_error{err, Q, sqlstate, -1, loc}
601 {}
602#else
604 std::string const &err, std::string const &Q = "",
605 char const sqlstate[] = nullptr) :
606 syntax_error{err, Q, sqlstate}
607 {}
608#endif
609};
610
611struct PQXX_LIBEXPORT insufficient_privilege : sql_error
612{
613#if pqxx_have_source_location
614 explicit insufficient_privilege(
615 std::string const &err, std::string const &Q = "",
616 char const sqlstate[] = nullptr,
617 std::source_location loc = std::source_location::current()) :
618 sql_error{err, Q, sqlstate, loc}
619 {}
620#else
622 std::string const &err, std::string const &Q = "",
623 char const sqlstate[] = nullptr) :
624 sql_error{err, Q, sqlstate}
625 {}
626#endif
627};
628
630struct PQXX_LIBEXPORT insufficient_resources : sql_error
631{
632#if pqxx_have_source_location
633 explicit insufficient_resources(
634 std::string const &err, std::string const &Q = "",
635 char const sqlstate[] = nullptr,
636 std::source_location loc = std::source_location::current()) :
637 sql_error{err, Q, sqlstate, loc}
638 {}
639#else
641 std::string const &err, std::string const &Q = "",
642 char const sqlstate[] = nullptr) :
643 sql_error{err, Q, sqlstate}
644 {}
645#endif
646};
647
648struct PQXX_LIBEXPORT disk_full : insufficient_resources
649{
650#if pqxx_have_source_location
651 explicit disk_full(
652 std::string const &err, std::string const &Q = "",
653 char const sqlstate[] = nullptr,
654 std::source_location loc = std::source_location::current()) :
655 insufficient_resources{err, Q, sqlstate, loc}
656 {}
657#else
658 explicit disk_full(
659 std::string const &err, std::string const &Q = "",
660 char const sqlstate[] = nullptr) :
661 insufficient_resources{err, Q, sqlstate}
662 {}
663#endif
664};
665
667{
668#if pqxx_have_source_location
669 explicit out_of_memory(
670 std::string const &err, std::string const &Q = "",
671 char const sqlstate[] = nullptr,
672 std::source_location loc = std::source_location::current()) :
673 insufficient_resources{err, Q, sqlstate, loc}
674 {}
675#else
677 std::string const &err, std::string const &Q = "",
678 char const sqlstate[] = nullptr) :
679 insufficient_resources{err, Q, sqlstate}
680 {}
681#endif
682};
683
685{
686#if pqxx_have_source_location
687 explicit too_many_connections(
688 std::string const &err,
689 std::source_location loc = std::source_location::current()
690 ) :
691 broken_connection{err, loc}
692 {}
693#else
694 explicit too_many_connections(std::string const &err) :
696 {}
697#endif
698};
699
701
703struct PQXX_LIBEXPORT plpgsql_error : sql_error
704{
705#if pqxx_have_source_location
706 explicit plpgsql_error(
707 std::string const &err, std::string const &Q = "",
708 char const sqlstate[] = nullptr,
709 std::source_location loc = std::source_location::current()) :
710 sql_error{err, Q, sqlstate, loc}
711 {}
712#else
714 std::string const &err, std::string const &Q = "",
715 char const sqlstate[] = nullptr) :
716 sql_error{err, Q, sqlstate}
717 {}
718#endif
719};
720
722struct PQXX_LIBEXPORT plpgsql_raise : plpgsql_error
723{
724#if pqxx_have_source_location
725 explicit plpgsql_raise(
726 std::string const &err, std::string const &Q = "",
727 char const sqlstate[] = nullptr,
728 std::source_location loc = std::source_location::current()) :
729 plpgsql_error{err, Q, sqlstate, loc}
730 {}
731#else
733 std::string const &err, std::string const &Q = "",
734 char const sqlstate[] = nullptr) :
735 plpgsql_error{err, Q, sqlstate}
736 {}
737#endif
738};
739
741{
742#if pqxx_have_source_location
743 explicit plpgsql_no_data_found(
744 std::string const &err, std::string const &Q = "",
745 char const sqlstate[] = nullptr,
746 std::source_location loc = std::source_location::current()) :
747 plpgsql_error{err, Q, sqlstate, loc}
748 {}
749#else
751 std::string const &err, std::string const &Q = "",
752 char const sqlstate[] = nullptr) :
753 plpgsql_error{err, Q, sqlstate}
754 {}
755#endif
756};
757
759{
760#if pqxx_have_source_location
761 explicit plpgsql_too_many_rows(
762 std::string const &err, std::string const &Q = "",
763 char const sqlstate[] = nullptr,
764 std::source_location loc = std::source_location::current()) :
765 plpgsql_error{err, Q, sqlstate, loc}
766 {}
767#else
769 std::string const &err, std::string const &Q = "",
770 char const sqlstate[] = nullptr) :
771 plpgsql_error{err, Q, sqlstate}
772 {}
773#endif
774};
775
779} // namespace pqxx
780#endif
The home of all libpqxx classes, functions, templates, etc.
Definition array.hxx:33
Run-time failure encountered by libpqxx, similar to std::runtime_error.
Definition except.hxx:48
Exception class for lost or failed backend connection.
Definition except.hxx:82
Exception class for micommunication with the server.
Definition except.hxx:102
The caller attempted to set a variable to null, which is not allowed.
Definition except.hxx:113
Exception class for failed queries.
Definition except.hxx:128
virtual ~sql_error() noexcept override
"Help, I don't know whether transaction was committed successfully!"
Definition except.hxx:160
The backend saw itself forced to roll back the ongoing transaction.
Definition except.hxx:171
Transaction failed to serialize. Please retry it.
Definition except.hxx:192
We can't tell whether our last statement succeeded.
Definition except.hxx:205
The ongoing transaction has deadlocked. Retrying it may help.
Definition except.hxx:218
Internal error in libpqxx library.
Definition except.hxx:231
Error in usage of libpqxx library, similar to std::logic_error.
Definition except.hxx:238
Invalid argument passed to libpqxx, similar to std::invalid_argument.
Definition except.hxx:253
Value conversion failed, e.g. when converting "Hello" to int.
Definition except.hxx:268
Could not convert null value: target type does not support null.
Definition except.hxx:283
Could not convert value to string: not enough buffer space.
Definition except.hxx:294
Something is out of range, similar to std::out_of_range.
Definition except.hxx:305
Query returned an unexpected number of rows.
Definition except.hxx:320
unexpected_rows(std::string const &msg)
Definition except.hxx:328
Database feature not supported in current setup.
Definition except.hxx:335
feature_not_supported(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition except.hxx:344
Error in data provided to SQL statement.
Definition except.hxx:354
data_exception(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition except.hxx:363
Definition except.hxx:372
integrity_constraint_violation(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition except.hxx:381
Definition except.hxx:390
restrict_violation(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition except.hxx:399
Definition except.hxx:408
not_null_violation(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition except.hxx:417
Definition except.hxx:426
foreign_key_violation(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition except.hxx:435
Definition except.hxx:444
unique_violation(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition except.hxx:453
Definition except.hxx:462
check_violation(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition except.hxx:471
Definition except.hxx:480
invalid_cursor_state(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition except.hxx:489
Definition except.hxx:498
invalid_sql_statement_name(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition except.hxx:507
Definition except.hxx:516
invalid_cursor_name(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition except.hxx:525
Definition except.hxx:534
syntax_error(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr, int pos=-1)
Definition except.hxx:546
int const error_position
Approximate position in string where error occurred, or -1 if unknown.
Definition except.hxx:536
Definition except.hxx:555
undefined_column(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition except.hxx:565
Definition except.hxx:574
undefined_function(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition except.hxx:584
Definition except.hxx:593
undefined_table(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition except.hxx:603
Definition except.hxx:612
insufficient_privilege(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition except.hxx:621
Resource shortage on the server.
Definition except.hxx:631
insufficient_resources(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition except.hxx:640
Definition except.hxx:649
disk_full(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition except.hxx:658
Definition except.hxx:667
out_of_memory(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition except.hxx:676
Definition except.hxx:685
too_many_connections(std::string const &err)
Definition except.hxx:694
PL/pgSQL error.
Definition except.hxx:704
plpgsql_error(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition except.hxx:713
Exception raised in PL/pgSQL procedure.
Definition except.hxx:723
plpgsql_raise(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition except.hxx:732
Definition except.hxx:741
plpgsql_no_data_found(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition except.hxx:750
Definition except.hxx:759
plpgsql_too_many_rows(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition except.hxx:768