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