13 #ifndef PQXX_EXCEPT_HXX
14 #define PQXX_EXCEPT_HXX
16 #if !defined(PQXX_HEADER_PRE)
17 # error "Include libpqxx headers as <pqxx/header>, not <pqxx/header.hxx>."
80 m_block{std::make_shared<block>(loc, std::move(tr))}
85 std::make_shared<block>(std::move(whatarg), loc, std::move(tr))}
94 [[nodiscard]]
PQXX_PURE char const *what() const noexcept
override
96 return m_block->message.c_str();
106 return m_block->location;
125 return m_block->trace;
135 return m_block->sqlstate;
146 return m_block->statement;
216 [[nodiscard]]
virtual std::string_view name() const noexcept;
222 std::
string whatarg, std::
string stat, std::
string sqls,
223 sl loc =
sl::current(),
st tr =
st::current()) :
224 m_block{std::make_shared<block>(
225 std::move(whatarg), std::move(stat), std::move(sqls), loc,
238 std::string statement;
240 std::string sqlstate;
244 std::shared_ptr<st const> trace;
248 block(
sl loc,
st &&tr) :
249 location{loc}, trace{make_trace_ptr(std::move(tr))}
252 block(std::string &&msg,
sl loc,
st &&tr) :
253 message{std::move(msg)},
255 trace{make_trace_ptr(std::move(tr))}
259 std::string &&msg, std::string &&stat, std::string &&sqls,
sl loc,
261 message{std::move(msg)},
262 statement{std::move(stat)},
263 sqlstate{std::move(sqls)},
265 trace{make_trace_ptr(std::move(tr))}
273 [[nodiscard]]
static std::shared_ptr<st const>
274 make_trace_ptr([[maybe_unused]]
st &&tr)
276 #if defined(PQXX_HAVE_STACKTRACE)
278 return std::make_shared<st const>(std::move(tr));
291 std::shared_ptr<block const> m_block;
318 failure{
"Connection to database failed.", loc, std::move(tr)}
322 std::string
const &whatarg,
sl loc = sl::current(),
324 failure{whatarg, loc, std::move(tr)}
327 [[nodiscard]] std::string_view name() const noexcept override;
330 [[nodiscard]]
bool poisons_connection() const noexcept
override
347 std::string
const &whatarg,
sl loc = sl::current(),
352 [[nodiscard]] std::string_view name() const noexcept override;
360 std::string
const &whatarg,
sl loc = sl::current(),
362 failure{whatarg, loc, std::move(tr)}
365 [[nodiscard]] std::string_view name() const noexcept override;
384 std::string
const &whatarg = {}, std::string
const &stmt = {},
385 std::string
const &sqls = {},
sl loc = sl::current(),
387 failure{whatarg, stmt, sqls, loc, std::move(tr)}
396 [[nodiscard]] std::string_view name() const noexcept override;
399 [[nodiscard]]
bool poisons_transaction() const noexcept
override
421 std::string
const &whatarg, std::string
const &stmt = {},
422 std::string
const &sqls = {},
sl loc = sl::current(),
424 sql_error{whatarg, stmt, sqls, loc, std::move(tr)}
439 [[nodiscard]] std::string_view name() const noexcept override;
453 std::string
const &whatarg,
sl loc = sl::current(),
455 failure{whatarg, loc, std::move(tr)}
470 [[nodiscard]] std::string_view name() const noexcept override;
478 std::string
const &whatarg, std::string
const &q = {},
479 std::string
const &sqlstate = {},
sl loc = sl::current(),
481 sql_error{whatarg, q, sqlstate, loc, std::move(tr)}
490 [[nodiscard]] std::string_view name() const noexcept override;
506 std::string
const &whatarg, std::string
const &q,
507 std::string
const &sqlstate = {},
sl loc = sl::current(),
518 [[nodiscard]] std::string_view name() const noexcept override;
526 std::string
const &whatarg, std::string
const &q,
527 std::string
const &sqlstate = {},
sl loc = sl::current(),
538 [[nodiscard]] std::string_view name() const noexcept override;
546 std::string
const &whatarg, std::string
const &q,
547 std::string
const &sqlstate = {},
sl loc = sl::current(),
552 [[nodiscard]] std::string_view name() const noexcept override;
574 [[nodiscard]] std::string_view name() const noexcept override;
582 std::string
const &whatarg,
sl loc = sl::current(),
584 failure{whatarg, loc, std::move(tr)}
593 [[nodiscard]] std::string_view name() const noexcept override;
601 std::string
const &whatarg,
sl loc = sl::current(),
603 failure{whatarg, loc, std::move(tr)}
606 [[nodiscard]] std::string_view name() const noexcept override;
614 std::string
const &whatarg,
sl loc = sl::current(),
616 failure{whatarg, loc, std::move(tr)}
619 [[nodiscard]] std::string_view name() const noexcept override;
627 std::string
const &whatarg,
sl loc = sl::current(),
632 [[nodiscard]] std::string_view name() const noexcept override;
640 std::string
const &whatarg,
sl loc = sl::current(),
645 [[nodiscard]] std::string_view name() const noexcept override;
653 std::string
const &whatarg,
sl loc = sl::current(),
655 failure{whatarg, loc, std::move(tr)}
658 [[nodiscard]] std::string_view name() const noexcept override;
666 std::string
const &msg,
sl loc = sl::current(),
st &&tr =
st::current()) :
670 [[nodiscard]] std::string_view name() const noexcept override;
678 std::string
const &err, std::string
const &Q = {},
679 std::string
const &sqlstate = {},
sl loc = sl::current(),
681 sql_error{err, Q, sqlstate, loc, std::move(tr)}
684 [[nodiscard]] std::string_view name() const noexcept override;
687 [[nodiscard]]
bool poisons_connection() const noexcept
override
704 std::string
const &err, std::string
const &Q = {},
705 std::string
const &sqlstate = {},
sl loc = sl::current(),
707 sql_error{err, Q, sqlstate, loc, std::move(tr)}
710 [[nodiscard]] std::string_view name() const noexcept override;
717 std::string
const &err, std::string
const &Q = {},
718 std::string
const &sqlstate = {},
sl loc = sl::current(),
720 sql_error{err, Q, sqlstate, loc, std::move(tr)}
723 [[nodiscard]] std::string_view name() const noexcept override;
730 std::string
const &err, std::string
const &Q = {},
731 std::string
const &sqlstate = {},
sl loc = sl::current(),
733 integrity_constraint_violation{err, Q, sqlstate, loc, std::move(tr)}
736 [[nodiscard]] std::string_view name() const noexcept override;
743 std::string
const &err, std::string
const &Q = {},
744 std::string
const &sqlstate = {},
sl loc = sl::current(),
746 integrity_constraint_violation{err, Q, sqlstate, loc, std::move(tr)}
749 [[nodiscard]] std::string_view name() const noexcept override;
756 std::string
const &err, std::string
const &Q = {},
757 std::string
const &sqlstate = {},
sl loc = sl::current(),
759 integrity_constraint_violation{err, Q, sqlstate, loc, std::move(tr)}
762 [[nodiscard]] std::string_view name() const noexcept override;
769 std::string
const &err, std::string
const &Q = {},
770 std::string
const &sqlstate = {},
sl loc = sl::current(),
772 integrity_constraint_violation{err, Q, sqlstate, loc, std::move(tr)}
775 [[nodiscard]] std::string_view name() const noexcept override;
782 std::string
const &err, std::string
const &Q = {},
783 std::string
const &sqlstate = {},
sl loc = sl::current(),
785 integrity_constraint_violation{err, Q, sqlstate, loc, std::move(tr)}
788 [[nodiscard]] std::string_view name() const noexcept override;
795 std::string
const &err, std::string
const &Q = {},
796 std::string
const &sqlstate = {},
sl loc = sl::current(),
798 sql_error{err, Q, sqlstate, loc, std::move(tr)}
801 [[nodiscard]] std::string_view name() const noexcept override;
808 std::string
const &err, std::string
const &Q = {},
809 std::string
const &sqlstate = {},
sl loc = sl::current(),
811 sql_error{err, Q, sqlstate, loc, std::move(tr)}
814 [[nodiscard]] std::string_view name() const noexcept override;
821 std::string
const &err, std::string
const &Q = {},
822 std::string
const &sqlstate = {},
sl loc = sl::current(),
824 sql_error{err, Q, sqlstate, loc, std::move(tr)}
827 [[nodiscard]] std::string_view name() const noexcept override;
839 std::string
const &err, std::string
const &Q = {},
840 std::string
const &sqlstate = {},
int pos = -1,
sl loc = sl::current(),
842 sql_error{err, Q, sqlstate, loc, std::move(tr)}, error_position{pos}
847 [[nodiscard]] std::string_view name() const noexcept override;
853 [[nodiscard]] constexpr
int error_pos() const noexcept
856 return error_position;
865 std::string
const &err, std::string
const &Q = {},
866 std::string
const &sqlstate = {},
sl loc = sl::current(),
869 syntax_error{err, Q, sqlstate, -1, loc, std::move(tr)}
872 [[nodiscard]] std::string_view name() const noexcept override;
879 std::string
const &err, std::string
const &Q = {},
880 std::string
const &sqlstate = {},
sl loc = sl::current(),
883 syntax_error{err, Q, sqlstate, -1, loc, std::move(tr)}
886 [[nodiscard]] std::string_view name() const noexcept override;
893 std::string
const &err, std::string
const &Q = {},
894 std::string
const &sqlstate = {},
sl loc = sl::current(),
897 syntax_error{err, Q, sqlstate, -1, loc, std::move(tr)}
900 [[nodiscard]] std::string_view name() const noexcept override;
907 std::string
const &err, std::string
const &Q = {},
908 std::string
const &sqlstate = {},
sl loc = sl::current(),
910 sql_error{err, Q, sqlstate, loc, std::move(tr)}
913 [[nodiscard]] std::string_view name() const noexcept override;
921 std::string
const &err, std::string
const &Q = {},
922 std::string
const &sqlstate = {},
sl loc = sl::current(),
924 sql_error{err, Q, sqlstate, loc, std::move(tr)}
927 [[nodiscard]] std::string_view name() const noexcept override;
934 std::string
const &err, std::string
const &Q = {},
935 std::string
const &sqlstate = {},
sl loc = sl::current(),
937 insufficient_resources{err, Q, sqlstate, loc, std::move(tr)}
940 [[nodiscard]] std::string_view name() const noexcept override;
947 std::string
const &err, std::string
const &Q = {},
948 std::string
const &sqlstate = {},
sl loc = sl::current(),
950 insufficient_resources{err, Q, sqlstate, loc, std::move(tr)}
953 [[nodiscard]] std::string_view name() const noexcept override;
960 std::string
const &err,
sl loc = sl::current(),
st &&tr =
st::current()) :
964 [[nodiscard]] std::string_view name() const noexcept override;
974 std::string
const &err, std::string
const &Q = {},
975 std::string
const &sqlstate = {},
sl loc = sl::current(),
977 sql_error{err, Q, sqlstate, loc, std::move(tr)}
980 [[nodiscard]] std::string_view name() const noexcept override;
988 std::string
const &err, std::string
const &Q = {},
989 std::string
const &sqlstate = {},
sl loc = sl::current(),
991 plpgsql_error{err, Q, sqlstate, loc, std::move(tr)}
994 [[nodiscard]] std::string_view name() const noexcept override;
1001 std::string
const &err, std::string
const &Q = {},
1002 std::string
const &sqlstate = {},
sl loc = sl::current(),
1004 plpgsql_error{err, Q, sqlstate, loc, std::move(tr)}
1007 [[nodiscard]] std::string_view name() const noexcept override;
1014 std::string
const &err, std::string
const &Q = {},
1015 std::string
const &sqlstate = {},
sl loc = sl::current(),
1017 plpgsql_error{err, Q, sqlstate, loc, std::move(tr)}
1020 [[nodiscard]] std::string_view name() const noexcept override;
PQXX_ZARGS disk_full(std::string const &err, std::string const &Q={}, std::string const &sqlstate={}, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:933
bool poisons_transaction() const noexcept override
Some earlier failure broke the transaction.
Definition: except.hxx:485
in_doubt_error(std::string const &whatarg, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:452
PQXX_ZARGS foreign_key_violation(std::string const &err, std::string const &Q={}, std::string const &sqlstate={}, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:755
variable_set_to_null(std::string const &whatarg, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:359
virtual bool poisons_connection() const noexcept
Does this type of error make the current connection unusable?
Definition: except.hxx:161
PQXX_ZARGS data_exception(std::string const &err, std::string const &Q={}, std::string const &sqlstate={}, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:703
~failure() noexcept override
failure(failure const &)=default
PQXX_ZARGS integrity_constraint_violation(std::string const &err, std::string const &Q={}, std::string const &sqlstate={}, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:716
PQXX_ZARGS deadlock_detected(std::string const &whatarg, std::string const &q, std::string const &sqlstate={}, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:545
PQXX_ZARGS plpgsql_too_many_rows(std::string const &err, std::string const &Q={}, std::string const &sqlstate={}, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:1013
bool poisons_connection() const noexcept override
When this happens, all bets are off. It may work, but don't risk it.
Definition: except.hxx:563
PQXX_ZARGS insufficient_resources(std::string const &err, std::string const &Q={}, std::string const &sqlstate={}, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:920
PQXX_PURE std::string_view sqlstate() const noexcept
SQLSTATE error code, or empty string if unavailable.
Definition: except.hxx:133
bool poisons_connection() const noexcept override
It's not advisable to continue using the connection after this.
Definition: except.hxx:533
PQXX_ZARGS transaction_rollback(std::string const &whatarg, std::string const &q={}, std::string const &sqlstate={}, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:477
PQXX_ZARGS server_out_of_memory(std::string const &err, std::string const &Q={}, std::string const &sqlstate={}, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:946
PQXX_PURE std::string_view query() const noexcept
SQL statement that encountered the error, if applicable; or empty string.
Definition: except.hxx:144
PQXX_ZARGS undefined_column(std::string const &err, std::string const &Q={}, std::string const &sqlstate={}, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:864
bool poisons_connection() const noexcept override
This kind of error can only happen when the connection breaks.
Definition: except.hxx:459
bool poisons_transaction() const noexcept override
Since the connection is broken, so is a transaction.
Definition: except.hxx:434
int error_position
Definition: except.hxx:834
PQXX_ZARGS syntax_error(std::string const &err, std::string const &Q={}, std::string const &sqlstate={}, int pos=-1, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:838
broken_connection(sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:317
PQXX_ZARGS unique_violation(std::string const &err, std::string const &Q={}, std::string const &sqlstate={}, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:768
PQXX_ZARGS feature_not_supported(std::string const &err, std::string const &Q={}, std::string const &sqlstate={}, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:677
PQXX_ZARGS not_null_violation(std::string const &err, std::string const &Q={}, std::string const &sqlstate={}, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:742
bool poisons_transaction() const noexcept override
When this happens, all bets are off. It may work, but don't risk it.
Definition: except.hxx:569
bool poisons_transaction() const noexcept override
To retry the transaction, you'll need to start a fresh one.
Definition: except.hxx:513
bool poisons_connection() const noexcept override
When this happens, the connection is in a confused state.
Definition: except.hxx:428
PQXX_ZARGS statement_completion_unknown(std::string const &whatarg, std::string const &q, std::string const &sqlstate={}, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:525
PQXX_ZARGS check_violation(std::string const &err, std::string const &Q={}, std::string const &sqlstate={}, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:781
broken_connection(std::string const &whatarg, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:321
failure(failure &&)=default
PQXX_ZARGS invalid_cursor_name(std::string const &err, std::string const &Q={}, std::string const &sqlstate={}, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:820
PQXX_ZARGS invalid_cursor_state(std::string const &err, std::string const &Q={}, std::string const &sqlstate={}, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:794
PQXX_ZARGS plpgsql_no_data_found(std::string const &err, std::string const &Q={}, std::string const &sqlstate={}, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:1000
PQXX_ZARGS serialization_failure(std::string const &whatarg, std::string const &q, std::string const &sqlstate={}, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:505
bool poisons_transaction() const noexcept override
Your transaction will probably still work, but something is badly wrong.
Definition: except.hxx:588
version_mismatch(std::string const &whatarg, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:346
usage_error(std::string const &whatarg, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:581
conversion_error(std::string const &whatarg, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:613
conversion_overrun(std::string const &whatarg, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:639
bool poisons_transaction() const noexcept override
When the connection breaks, so will an ongoing transaction.
Definition: except.hxx:336
range_error(std::string const &whatarg, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:652
sql_error & operator=(sql_error const &other)=default
bool poisons_transaction() const noexcept override
If this poisons your connection, it also poisons your transaction.
Definition: except.hxx:693
PQXX_ZARGS plpgsql_raise(std::string const &err, std::string const &Q={}, std::string const &sqlstate={}, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:987
PQXX_ZARGS sql_error(std::string const &whatarg={}, std::string const &stmt={}, std::string const &sqls={}, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:383
unexpected_null(std::string const &whatarg, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:626
PQXX_ZARGS plpgsql_error(std::string const &err, std::string const &Q={}, std::string const &sqlstate={}, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:973
sql_error & operator=(sql_error &&other)=default
virtual bool poisons_transaction() const noexcept
Does this type of error make an ongoing dbtransaction unusable?
Definition: except.hxx:180
PQXX_ZARGS insufficient_privilege(std::string const &err, std::string const &Q={}, std::string const &sqlstate={}, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:906
PQXX_ZARGS restrict_violation(std::string const &err, std::string const &Q={}, std::string const &sqlstate={}, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:729
failure(std::string whatarg, sl loc=sl::current(), st tr=st::current())
Definition: except.hxx:82
unexpected_rows(std::string const &msg, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:665
sql_error(sql_error &&other)=default
too_many_connections(std::string const &err, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:959
bool poisons_transaction() const noexcept override
The transaction is already closed, and the connection is broken.
Definition: except.hxx:465
argument_error(std::string const &whatarg, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:600
PQXX_PURE std::shared_ptr< st const > trace() const noexcept
If available in this compiler, a std::stacktrace of this exception.
Definition: except.hxx:123
PQXX_ZARGS undefined_function(std::string const &err, std::string const &Q={}, std::string const &sqlstate={}, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:878
PQXX_ZARGS invalid_sql_statement_name(std::string const &err, std::string const &Q={}, std::string const &sqlstate={}, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:807
failure(sl loc=sl::current(), st tr=st::current())
Definition: except.hxx:79
protocol_violation(std::string const &whatarg, std::string const &stmt={}, std::string const &sqls={}, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:420
~sql_error() override=default
sql_error(sql_error const &other)=default
PQXX_PURE sl const & location() const noexcept
Best known std::source_location for where the error occurred.
Definition: except.hxx:104
PQXX_ZARGS undefined_table(std::string const &err, std::string const &Q={}, std::string const &sqlstate={}, sl loc=sl::current(), st &&tr=st::current())
Definition: except.hxx:892
Invalid argument passed to libpqxx, similar to std::invalid_argument.
Definition: except.hxx:599
Exception class for lost or failed backend connection.
Definition: except.hxx:316
Definition: except.hxx:780
Value conversion failed, e.g. when converting "Hello" to int.
Definition: except.hxx:612
Could not convert value to string: not enough buffer space.
Definition: except.hxx:638
Error in data provided to SQL statement.
Definition: except.hxx:702
The ongoing transaction has deadlocked. Retrying it may help.
Definition: except.hxx:544
Definition: except.hxx:932
Base class for all exceptions specific to libpqxx.
Definition: except.hxx:76
Database feature not supported in current setup.
Definition: except.hxx:676
Definition: except.hxx:754
"Help, I don't know whether transaction was committed successfully!"
Definition: except.hxx:451
Definition: except.hxx:905
Resource shortage on the server.
Definition: except.hxx:919
Definition: except.hxx:715
Internal error in libpqxx library.
Definition: except.hxx:558
Definition: except.hxx:819
Definition: except.hxx:793
Definition: except.hxx:806
Definition: except.hxx:741
PL/pgSQL error.
Definition: except.hxx:972
Definition: except.hxx:999
Exception raised in PL/pgSQL procedure.
Definition: except.hxx:986
Definition: except.hxx:1012
Exception class for mis-communication with the server.
Definition: except.hxx:419
Something is out of range, similar to std::out_of_range.
Definition: except.hxx:651
Definition: except.hxx:728
Transaction failed to serialize. Please retry the whole thing.
Definition: except.hxx:504
Definition: except.hxx:945
Exception class for failed queries.
Definition: except.hxx:382
We can't tell whether our last statement succeeded.
Definition: except.hxx:524
Definition: except.hxx:832
Definition: except.hxx:958
The backend saw itself forced to roll back the ongoing transaction.
Definition: except.hxx:476
Definition: except.hxx:863
Definition: except.hxx:877
Definition: except.hxx:891
Could not convert null value: target type does not support null.
Definition: except.hxx:625
Query returned an unexpected number of rows.
Definition: except.hxx:664
Definition: except.hxx:767
Error in usage of libpqxx library, similar to std::logic_error.
Definition: except.hxx:580
The caller attempted to set a variable to null, which is not allowed.
Definition: except.hxx:358
Could not establish connection due to version mismatch.
Definition: except.hxx:345
The home of all libpqxx classes, functions, templates, etc.
Definition: array.cxx:26
std::source_location sl
Convenience alias for std::source_location. It's just too long.
Definition: types.hxx:38
stacktrace_placeholder st
Placeholder for future std::stacktrace.
Definition: types.hxx:68
There is no std::stacktrace on this system. Use a placeholder.
Definition: types.hxx:46
static constexpr PQXX_PURE stacktrace_placeholder current() noexcept
Placeholder for std::stacktrace::current().
Definition: types.hxx:62