Loading...
Searching...
No Matches
except.hxx
/* Definition of libpqxx exception classes.
*
* pqxx::sql_error, pqxx::broken_connection, pqxx::in_doubt_error, ...
*
* DO NOT INCLUDE THIS FILE DIRECTLY; include pqxx/except instead.
*
* Copyright (c) 2000-2024, Jeroen T. Vermeulen.
*
* See COPYING for copyright license. If you did not receive a file called
* COPYING with this source code, please notify the distributor of this
* mistake, or contact the author.
*/
#ifndef PQXX_H_EXCEPT
#define PQXX_H_EXCEPT
#if !defined(PQXX_HEADER_PRE)
# error "Include libpqxx headers as <pqxx/header>, not <pqxx/header.hxx>."
#endif
#if defined(PQXX_HAVE_SOURCE_LOCATION)
# include <source_location>
#endif
#include <stdexcept>
#include <string>
namespace pqxx
{
struct PQXX_LIBEXPORT failure : std::runtime_error
{
#if defined(PQXX_HAVE_SOURCE_LOCATION)
explicit failure(
std::string const &,
std::source_location = std::source_location::current());
std::source_location location;
#else
explicit failure(std::string const &);
#endif
};
struct PQXX_LIBEXPORT broken_connection : failure
{
broken_connection();
explicit broken_connection(
std::string const &
#if defined(PQXX_HAVE_SOURCE_LOCATION)
,
std::source_location = std::source_location::current()
#endif
);
};
struct PQXX_LIBEXPORT protocol_violation : broken_connection
{
explicit protocol_violation(
std::string const &
#if defined(PQXX_HAVE_SOURCE_LOCATION)
,
std::source_location = std::source_location::current()
#endif
);
};
struct PQXX_LIBEXPORT variable_set_to_null : failure
{
explicit variable_set_to_null(
std::string const &
#if defined(PQXX_HAVE_SOURCE_LOCATION)
,
std::source_location = std::source_location::current()
#endif
);
};
class PQXX_LIBEXPORT sql_error : public failure
{
std::string const m_query;
std::string const m_sqlstate;
public:
explicit sql_error(
std::string const &whatarg = "", std::string Q = "",
char const *sqlstate = nullptr
#if defined(PQXX_HAVE_SOURCE_LOCATION)
,
std::source_location = std::source_location::current()
#endif
);
virtual ~sql_error() noexcept override;
[[nodiscard]] PQXX_PURE std::string const &query() const noexcept;
[[nodiscard]] PQXX_PURE std::string const &sqlstate() const noexcept;
};
struct PQXX_LIBEXPORT in_doubt_error : failure
{
explicit in_doubt_error(
std::string const &
#if defined(PQXX_HAVE_SOURCE_LOCATION)
,
std::source_location = std::source_location::current()
#endif
);
};
struct PQXX_LIBEXPORT transaction_rollback : sql_error
{
explicit transaction_rollback(
std::string const &whatarg, std::string const &q = "",
char const sqlstate[] = nullptr
#if defined(PQXX_HAVE_SOURCE_LOCATION)
,
std::source_location = std::source_location::current()
#endif
);
};
struct PQXX_LIBEXPORT serialization_failure : transaction_rollback
{
explicit serialization_failure(
std::string const &whatarg, std::string const &q,
char const sqlstate[] = nullptr
#if defined(PQXX_HAVE_SOURCE_LOCATION)
,
std::source_location = std::source_location::current()
#endif
);
};
struct PQXX_LIBEXPORT statement_completion_unknown : transaction_rollback
{
explicit statement_completion_unknown(
std::string const &whatarg, std::string const &q,
char const sqlstate[] = nullptr
#if defined(PQXX_HAVE_SOURCE_LOCATION)
,
std::source_location = std::source_location::current()
#endif
);
};
struct PQXX_LIBEXPORT deadlock_detected : transaction_rollback
{
explicit deadlock_detected(
std::string const &whatarg, std::string const &q,
char const sqlstate[] = nullptr
#if defined(PQXX_HAVE_SOURCE_LOCATION)
,
std::source_location = std::source_location::current()
#endif
);
};
struct PQXX_LIBEXPORT internal_error : std::logic_error
{
explicit internal_error(std::string const &);
};
struct PQXX_LIBEXPORT usage_error : std::logic_error
{
explicit usage_error(
std::string const &
#if defined(PQXX_HAVE_SOURCE_LOCATION)
,
std::source_location = std::source_location::current()
#endif
);
#if defined(PQXX_HAVE_SOURCE_LOCATION)
std::source_location location;
#endif
};
struct PQXX_LIBEXPORT argument_error : std::invalid_argument
{
explicit argument_error(
std::string const &
#if defined(PQXX_HAVE_SOURCE_LOCATION)
,
std::source_location = std::source_location::current()
#endif
);
#if defined(PQXX_HAVE_SOURCE_LOCATION)
std::source_location location;
#endif
};
struct PQXX_LIBEXPORT conversion_error : std::domain_error
{
explicit conversion_error(
std::string const &
#if defined(PQXX_HAVE_SOURCE_LOCATION)
,
std::source_location = std::source_location::current()
#endif
);
#if defined(PQXX_HAVE_SOURCE_LOCATION)
std::source_location location;
#endif
};
struct PQXX_LIBEXPORT unexpected_null : conversion_error
{
explicit unexpected_null(
std::string const &
#if defined(PQXX_HAVE_SOURCE_LOCATION)
,
std::source_location = std::source_location::current()
#endif
);
};
struct PQXX_LIBEXPORT conversion_overrun : conversion_error
{
explicit conversion_overrun(
std::string const &
#if defined(PQXX_HAVE_SOURCE_LOCATION)
,
std::source_location = std::source_location::current()
#endif
);
};
struct PQXX_LIBEXPORT range_error : std::out_of_range
{
explicit range_error(
std::string const &
#if defined(PQXX_HAVE_SOURCE_LOCATION)
,
std::source_location = std::source_location::current()
#endif
);
#if defined(PQXX_HAVE_SOURCE_LOCATION)
std::source_location location;
#endif
};
struct PQXX_LIBEXPORT unexpected_rows : public range_error
{
#if defined(PQXX_HAVE_SOURCE_LOCATION)
explicit unexpected_rows(
std::string const &msg,
std::source_location loc = std::source_location::current()) :
range_error{msg, loc}
{}
#else
explicit unexpected_rows(std::string const &msg) : range_error{msg} {}
#endif
};
struct PQXX_LIBEXPORT feature_not_supported : sql_error
{
#if defined(PQXX_HAVE_SOURCE_LOCATION)
explicit feature_not_supported(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr,
std::source_location loc = std::source_location::current()) :
sql_error{err, Q, sqlstate, loc}
{}
#else
explicit feature_not_supported(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr) :
sql_error{err, Q, sqlstate}
{}
#endif
};
struct PQXX_LIBEXPORT data_exception : sql_error
{
#if defined(PQXX_HAVE_SOURCE_LOCATION)
explicit data_exception(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr,
std::source_location loc = std::source_location::current()) :
sql_error{err, Q, sqlstate, loc}
{}
#else
explicit data_exception(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr) :
sql_error{err, Q, sqlstate}
{}
#endif
};
struct PQXX_LIBEXPORT integrity_constraint_violation : sql_error
{
#if defined(PQXX_HAVE_SOURCE_LOCATION)
explicit integrity_constraint_violation(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr,
std::source_location loc = std::source_location::current()) :
sql_error{err, Q, sqlstate, loc}
{}
#else
explicit integrity_constraint_violation(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr) :
sql_error{err, Q, sqlstate}
{}
#endif
};
struct PQXX_LIBEXPORT restrict_violation : integrity_constraint_violation
{
#if defined(PQXX_HAVE_SOURCE_LOCATION)
explicit restrict_violation(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr,
std::source_location loc = std::source_location::current()) :
integrity_constraint_violation{err, Q, sqlstate, loc}
{}
#else
explicit restrict_violation(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr) :
integrity_constraint_violation{err, Q, sqlstate}
{}
#endif
};
struct PQXX_LIBEXPORT not_null_violation : integrity_constraint_violation
{
#if defined(PQXX_HAVE_SOURCE_LOCATION)
explicit not_null_violation(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr,
std::source_location loc = std::source_location::current()) :
integrity_constraint_violation{err, Q, sqlstate, loc}
{}
#else
explicit not_null_violation(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr) :
integrity_constraint_violation{err, Q, sqlstate}
{}
#endif
};
struct PQXX_LIBEXPORT foreign_key_violation : integrity_constraint_violation
{
#if defined(PQXX_HAVE_SOURCE_LOCATION)
explicit foreign_key_violation(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr,
std::source_location loc = std::source_location::current()) :
integrity_constraint_violation{err, Q, sqlstate, loc}
{}
#else
explicit foreign_key_violation(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr) :
integrity_constraint_violation{err, Q, sqlstate}
{}
#endif
};
struct PQXX_LIBEXPORT unique_violation : integrity_constraint_violation
{
#if defined(PQXX_HAVE_SOURCE_LOCATION)
explicit unique_violation(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr,
std::source_location loc = std::source_location::current()) :
integrity_constraint_violation{err, Q, sqlstate, loc}
{}
#else
explicit unique_violation(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr) :
integrity_constraint_violation{err, Q, sqlstate}
{}
#endif
};
struct PQXX_LIBEXPORT check_violation : integrity_constraint_violation
{
#if defined(PQXX_HAVE_SOURCE_LOCATION)
explicit check_violation(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr,
std::source_location loc = std::source_location::current()) :
integrity_constraint_violation{err, Q, sqlstate, loc}
{}
#else
explicit check_violation(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr) :
integrity_constraint_violation{err, Q, sqlstate}
{}
#endif
};
struct PQXX_LIBEXPORT invalid_cursor_state : sql_error
{
#if defined(PQXX_HAVE_SOURCE_LOCATION)
explicit invalid_cursor_state(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr,
std::source_location loc = std::source_location::current()) :
sql_error{err, Q, sqlstate, loc}
{}
#else
explicit invalid_cursor_state(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr) :
sql_error{err, Q, sqlstate}
{}
#endif
};
struct PQXX_LIBEXPORT invalid_sql_statement_name : sql_error
{
#if defined(PQXX_HAVE_SOURCE_LOCATION)
explicit invalid_sql_statement_name(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr,
std::source_location loc = std::source_location::current()) :
sql_error{err, Q, sqlstate, loc}
{}
#else
explicit invalid_sql_statement_name(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr) :
sql_error{err, Q, sqlstate}
{}
#endif
};
struct PQXX_LIBEXPORT invalid_cursor_name : sql_error
{
#if defined(PQXX_HAVE_SOURCE_LOCATION)
explicit invalid_cursor_name(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr,
std::source_location loc = std::source_location::current()) :
sql_error{err, Q, sqlstate, loc}
{}
#else
explicit invalid_cursor_name(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr) :
sql_error{err, Q, sqlstate}
{}
#endif
};
struct PQXX_LIBEXPORT syntax_error : sql_error
{
int const error_position;
#if defined(PQXX_HAVE_SOURCE_LOCATION)
explicit syntax_error(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr, int pos = -1,
std::source_location loc = std::source_location::current()) :
sql_error{err, Q, sqlstate, loc}, error_position{pos}
{}
#else
explicit syntax_error(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr, int pos = -1) :
sql_error{err, Q, sqlstate}, error_position{pos}
{}
#endif
};
struct PQXX_LIBEXPORT undefined_column : syntax_error
{
#if defined(PQXX_HAVE_SOURCE_LOCATION)
explicit undefined_column(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr,
std::source_location loc = std::source_location::current()) :
// TODO: Can we get the column?
syntax_error{err, Q, sqlstate, -1, loc}
{}
#else
explicit undefined_column(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr) :
syntax_error{err, Q, sqlstate}
{}
#endif
};
struct PQXX_LIBEXPORT undefined_function : syntax_error
{
#if defined(PQXX_HAVE_SOURCE_LOCATION)
explicit undefined_function(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr,
std::source_location loc = std::source_location::current()) :
// TODO: Can we get the column?
syntax_error{err, Q, sqlstate, -1, loc}
{}
#else
explicit undefined_function(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr) :
syntax_error{err, Q, sqlstate}
{}
#endif
};
struct PQXX_LIBEXPORT undefined_table : syntax_error
{
#if defined(PQXX_HAVE_SOURCE_LOCATION)
explicit undefined_table(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr,
std::source_location loc = std::source_location::current()) :
// TODO: Can we get the column?
syntax_error{err, Q, sqlstate, -1, loc}
{}
#else
explicit undefined_table(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr) :
syntax_error{err, Q, sqlstate}
{}
#endif
};
struct PQXX_LIBEXPORT insufficient_privilege : sql_error
{
#if defined(PQXX_HAVE_SOURCE_LOCATION)
explicit insufficient_privilege(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr,
std::source_location loc = std::source_location::current()) :
sql_error{err, Q, sqlstate, loc}
{}
#else
explicit insufficient_privilege(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr) :
sql_error{err, Q, sqlstate}
{}
#endif
};
struct PQXX_LIBEXPORT insufficient_resources : sql_error
{
#if defined(PQXX_HAVE_SOURCE_LOCATION)
explicit insufficient_resources(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr,
std::source_location loc = std::source_location::current()) :
sql_error{err, Q, sqlstate, loc}
{}
#else
explicit insufficient_resources(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr) :
sql_error{err, Q, sqlstate}
{}
#endif
};
struct PQXX_LIBEXPORT disk_full : insufficient_resources
{
#if defined(PQXX_HAVE_SOURCE_LOCATION)
explicit disk_full(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr,
std::source_location loc = std::source_location::current()) :
insufficient_resources{err, Q, sqlstate, loc}
{}
#else
explicit disk_full(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr) :
insufficient_resources{err, Q, sqlstate}
{}
#endif
};
struct PQXX_LIBEXPORT out_of_memory : insufficient_resources
{
#if defined(PQXX_HAVE_SOURCE_LOCATION)
explicit out_of_memory(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr,
std::source_location loc = std::source_location::current()) :
insufficient_resources{err, Q, sqlstate, loc}
{}
#else
explicit out_of_memory(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr) :
insufficient_resources{err, Q, sqlstate}
{}
#endif
};
struct PQXX_LIBEXPORT too_many_connections : broken_connection
{
#if defined(PQXX_HAVE_SOURCE_LOCATION)
explicit too_many_connections(
std::string const &err,
std::source_location loc = std::source_location::current()) :
broken_connection{err, loc}
{}
#else
explicit too_many_connections(std::string const &err) :
broken_connection{err}
{}
#endif
};
struct PQXX_LIBEXPORT plpgsql_error : sql_error
{
#if defined(PQXX_HAVE_SOURCE_LOCATION)
explicit plpgsql_error(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr,
std::source_location loc = std::source_location::current()) :
sql_error{err, Q, sqlstate, loc}
{}
#else
explicit plpgsql_error(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr) :
sql_error{err, Q, sqlstate}
{}
#endif
};
struct PQXX_LIBEXPORT plpgsql_raise : plpgsql_error
{
#if defined(PQXX_HAVE_SOURCE_LOCATION)
explicit plpgsql_raise(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr,
std::source_location loc = std::source_location::current()) :
plpgsql_error{err, Q, sqlstate, loc}
{}
#else
explicit plpgsql_raise(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr) :
plpgsql_error{err, Q, sqlstate}
{}
#endif
};
struct PQXX_LIBEXPORT plpgsql_no_data_found : plpgsql_error
{
#if defined(PQXX_HAVE_SOURCE_LOCATION)
explicit plpgsql_no_data_found(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr,
std::source_location loc = std::source_location::current()) :
plpgsql_error{err, Q, sqlstate, loc}
{}
#else
explicit plpgsql_no_data_found(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr) :
plpgsql_error{err, Q, sqlstate}
{}
#endif
};
struct PQXX_LIBEXPORT plpgsql_too_many_rows : plpgsql_error
{
#if defined(PQXX_HAVE_SOURCE_LOCATION)
explicit plpgsql_too_many_rows(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr,
std::source_location loc = std::source_location::current()) :
plpgsql_error{err, Q, sqlstate, loc}
{}
#else
explicit plpgsql_too_many_rows(
std::string const &err, std::string const &Q = "",
char const sqlstate[] = nullptr) :
plpgsql_error{err, Q, sqlstate}
{}
#endif
};
} // namespace pqxx
#endif
pqxx::sql_error::sqlstate
PQXX_PURE std::string const & sqlstate() const noexcept
SQLSTATE error code if known, or empty string otherwise.
pqxx::failure::failure
failure(std::string const &)
Definition except.cxx:23
pqxx::syntax_error::error_position
int const error_position
Approximate position in string where error occurred, or -1 if unknown.
Definition except.hxx:559
pqxx::sql_error::query
PQXX_PURE std::string const & query() const noexcept
The query whose execution triggered the exception.
pqxx::sql_error
Exception class for failed queries.
Definition except.hxx:132
pqxx::syntax_error
Definition except.hxx:557
pqxx
The home of all libpqxx classes, functions, templates, etc.
Definition array.cxx:27