libpqxx  7.7.4
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-2022, 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 #include <stdexcept>
21 #include <string>
22 
23 
24 namespace pqxx
25 {
42 struct PQXX_LIBEXPORT failure : std::runtime_error
44 {
45  explicit failure(std::string const &);
46 };
47 
48 
50 
68 struct PQXX_LIBEXPORT broken_connection : failure
69 {
71  explicit broken_connection(std::string const &);
72 };
73 
74 
76 struct PQXX_LIBEXPORT variable_set_to_null : failure
77 {
79  explicit variable_set_to_null(std::string const &);
80 };
81 
82 
84 
87 class PQXX_LIBEXPORT sql_error : public failure
88 {
90  std::string const m_query;
92  std::string const m_sqlstate;
93 
94 public:
95  explicit sql_error(
96  std::string const &whatarg = "", std::string const &Q = "",
97  char const sqlstate[] = nullptr);
98  virtual ~sql_error() noexcept override;
99 
101  [[nodiscard]] PQXX_PURE std::string const &query() const noexcept;
102 
104  [[nodiscard]] PQXX_PURE std::string const &sqlstate() const noexcept;
105 };
106 
107 
109 
115 struct PQXX_LIBEXPORT in_doubt_error : failure
116 {
117  explicit in_doubt_error(std::string const &);
118 };
119 
120 
122 struct PQXX_LIBEXPORT transaction_rollback : sql_error
123 {
124  explicit transaction_rollback(
125  std::string const &whatarg, std::string const &q = "",
126  char const sqlstate[] = nullptr);
127 };
128 
129 
131 
140 {
141  explicit serialization_failure(
142  std::string const &whatarg, std::string const &q,
143  char const sqlstate[] = nullptr);
144 };
145 
146 
149 {
151  std::string const &whatarg, std::string const &q,
152  char const sqlstate[] = nullptr);
153 };
154 
155 
158 {
159  explicit deadlock_detected(
160  std::string const &whatarg, std::string const &q,
161  char const sqlstate[] = nullptr);
162 };
163 
164 
166 struct PQXX_LIBEXPORT internal_error : std::logic_error
167 {
168  explicit internal_error(std::string const &);
169 };
170 
171 
173 struct PQXX_LIBEXPORT usage_error : std::logic_error
174 {
175  explicit usage_error(std::string const &);
176 };
177 
178 
180 struct PQXX_LIBEXPORT argument_error : std::invalid_argument
181 {
182  explicit argument_error(std::string const &);
183 };
184 
185 
187 struct PQXX_LIBEXPORT conversion_error : std::domain_error
188 {
189  explicit conversion_error(std::string const &);
190 };
191 
192 
194 struct PQXX_LIBEXPORT conversion_overrun : conversion_error
195 {
196  explicit conversion_overrun(std::string const &);
197 };
198 
199 
201 struct PQXX_LIBEXPORT range_error : std::out_of_range
202 {
203  explicit range_error(std::string const &);
204 };
205 
206 
208 struct PQXX_LIBEXPORT unexpected_rows : public range_error
209 {
210  explicit unexpected_rows(std::string const &msg) : range_error{msg} {}
211 };
212 
213 
215 struct PQXX_LIBEXPORT feature_not_supported : sql_error
216 {
218  std::string const &err, std::string const &Q = "",
219  char const sqlstate[] = nullptr) :
220  sql_error{err, Q, sqlstate}
221  {}
222 };
223 
225 struct PQXX_LIBEXPORT data_exception : sql_error
226 {
227  explicit data_exception(
228  std::string const &err, std::string const &Q = "",
229  char const sqlstate[] = nullptr) :
230  sql_error{err, Q, sqlstate}
231  {}
232 };
233 
235 {
237  std::string const &err, std::string const &Q = "",
238  char const sqlstate[] = nullptr) :
239  sql_error{err, Q, sqlstate}
240  {}
241 };
242 
244 {
246  std::string const &err, std::string const &Q = "",
247  char const sqlstate[] = nullptr) :
248  integrity_constraint_violation{err, Q, sqlstate}
249  {}
250 };
251 
253 {
255  std::string const &err, std::string const &Q = "",
256  char const sqlstate[] = nullptr) :
257  integrity_constraint_violation{err, Q, sqlstate}
258  {}
259 };
260 
262 {
264  std::string const &err, std::string const &Q = "",
265  char const sqlstate[] = nullptr) :
266  integrity_constraint_violation{err, Q, sqlstate}
267  {}
268 };
269 
271 {
273  std::string const &err, std::string const &Q = "",
274  char const sqlstate[] = nullptr) :
275  integrity_constraint_violation{err, Q, sqlstate}
276  {}
277 };
278 
280 {
281  explicit check_violation(
282  std::string const &err, std::string const &Q = "",
283  char const sqlstate[] = nullptr) :
284  integrity_constraint_violation{err, Q, sqlstate}
285  {}
286 };
287 
288 struct PQXX_LIBEXPORT invalid_cursor_state : sql_error
289 {
291  std::string const &err, std::string const &Q = "",
292  char const sqlstate[] = nullptr) :
293  sql_error{err, Q, sqlstate}
294  {}
295 };
296 
297 struct PQXX_LIBEXPORT invalid_sql_statement_name : sql_error
298 {
300  std::string const &err, std::string const &Q = "",
301  char const sqlstate[] = nullptr) :
302  sql_error{err, Q, sqlstate}
303  {}
304 };
305 
306 struct PQXX_LIBEXPORT invalid_cursor_name : sql_error
307 {
309  std::string const &err, std::string const &Q = "",
310  char const sqlstate[] = nullptr) :
311  sql_error{err, Q, sqlstate}
312  {}
313 };
314 
315 struct PQXX_LIBEXPORT syntax_error : sql_error
316 {
318  int const error_position;
319 
320  explicit syntax_error(
321  std::string const &err, std::string const &Q = "",
322  char const sqlstate[] = nullptr, int pos = -1) :
323  sql_error{err, Q, sqlstate}, error_position{pos}
324  {}
325 };
326 
327 struct PQXX_LIBEXPORT undefined_column : syntax_error
328 {
330  std::string const &err, std::string const &Q = "",
331  char const sqlstate[] = nullptr) :
332  syntax_error{err, Q, sqlstate}
333  {}
334 };
335 
336 struct PQXX_LIBEXPORT undefined_function : syntax_error
337 {
339  std::string const &err, std::string const &Q = "",
340  char const sqlstate[] = nullptr) :
341  syntax_error{err, Q, sqlstate}
342  {}
343 };
344 
345 struct PQXX_LIBEXPORT undefined_table : syntax_error
346 {
347  explicit undefined_table(
348  std::string const &err, std::string const &Q = "",
349  char const sqlstate[] = nullptr) :
350  syntax_error{err, Q, sqlstate}
351  {}
352 };
353 
354 struct PQXX_LIBEXPORT insufficient_privilege : sql_error
355 {
357  std::string const &err, std::string const &Q = "",
358  char const sqlstate[] = nullptr) :
359  sql_error{err, Q, sqlstate}
360  {}
361 };
362 
364 struct PQXX_LIBEXPORT insufficient_resources : sql_error
365 {
367  std::string const &err, std::string const &Q = "",
368  char const sqlstate[] = nullptr) :
369  sql_error{err, Q, sqlstate}
370  {}
371 };
372 
373 struct PQXX_LIBEXPORT disk_full : insufficient_resources
374 {
375  explicit disk_full(
376  std::string const &err, std::string const &Q = "",
377  char const sqlstate[] = nullptr) :
378  insufficient_resources{err, Q, sqlstate}
379  {}
380 };
381 
382 struct PQXX_LIBEXPORT out_of_memory : insufficient_resources
383 {
384  explicit out_of_memory(
385  std::string const &err, std::string const &Q = "",
386  char const sqlstate[] = nullptr) :
387  insufficient_resources{err, Q, sqlstate}
388  {}
389 };
390 
392 {
393  explicit too_many_connections(std::string const &err) :
394  broken_connection{err}
395  {}
396 };
397 
399 
401 struct PQXX_LIBEXPORT plpgsql_error : sql_error
402 {
403  explicit plpgsql_error(
404  std::string const &err, std::string const &Q = "",
405  char const sqlstate[] = nullptr) :
406  sql_error{err, Q, sqlstate}
407  {}
408 };
409 
411 struct PQXX_LIBEXPORT plpgsql_raise : plpgsql_error
412 {
413  explicit plpgsql_raise(
414  std::string const &err, std::string const &Q = "",
415  char const sqlstate[] = nullptr) :
416  plpgsql_error{err, Q, sqlstate}
417  {}
418 };
419 
420 struct PQXX_LIBEXPORT plpgsql_no_data_found : plpgsql_error
421 {
423  std::string const &err, std::string const &Q = "",
424  char const sqlstate[] = nullptr) :
425  plpgsql_error{err, Q, sqlstate}
426  {}
427 };
428 
429 struct PQXX_LIBEXPORT plpgsql_too_many_rows : plpgsql_error
430 {
432  std::string const &err, std::string const &Q = "",
433  char const sqlstate[] = nullptr) :
434  plpgsql_error{err, Q, sqlstate}
435  {}
436 };
437 
438 struct PQXX_LIBEXPORT blob_already_exists : failure
439 {
440  explicit blob_already_exists(std::string const &);
441 };
442 
446 } // namespace pqxx
447 #endif
data_exception(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:227
Something is out of range, similar to std::out_of_range.
Definition: except.hxx:201
Definition: except.hxx:382
Invalid argument passed to libpqxx, similar to std::invalid_argument.
Definition: except.hxx:180
Definition: except.hxx:354
invalid_cursor_state(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:290
Definition: except.hxx:270
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:26
Definition: except.hxx:243
too_many_connections(std::string const &err)
Definition: except.hxx:393
Definition: except.hxx:429
Database feature not supported in current setup.
Definition: except.hxx:215
PL/pgSQL error.
Definition: except.hxx:401
The caller attempted to set a variable to null, which is not allowed.
Definition: except.hxx:76
Definition: except.hxx:315
feature_not_supported(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:217
Definition: except.hxx:288
Definition: except.hxx:261
plpgsql_error(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:403
"Help, I don&#39;t know whether transaction was committed successfully!"
Definition: except.hxx:115
Definition: except.hxx:336
undefined_column(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:329
Exception class for lost or failed backend connection.
Definition: except.hxx:68
Definition: except.hxx:306
restrict_violation(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:245
out_of_memory(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:384
undefined_table(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:347
undefined_function(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:338
The ongoing transaction has deadlocked. Retrying it may help.
Definition: except.hxx:157
insufficient_privilege(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:356
The backend saw itself forced to roll back the ongoing transaction.
Definition: except.hxx:122
invalid_sql_statement_name(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:299
insufficient_resources(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:366
integrity_constraint_violation(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:236
Could not convert value to string: not enough buffer space.
Definition: except.hxx:194
Definition: except.hxx:373
plpgsql_raise(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:413
Error in usage of libpqxx library, similar to std::logic_error.
Definition: except.hxx:173
Definition: except.hxx:345
disk_full(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:375
syntax_error(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr, int pos=-1)
Definition: except.hxx:320
int const error_position
Approximate position in string where error occurred, or -1 if unknown.
Definition: except.hxx:318
Definition: except.hxx:234
plpgsql_no_data_found(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:422
Definition: except.hxx:420
not_null_violation(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:254
Query returned an unexpected number of rows.
Definition: except.hxx:208
foreign_key_violation(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:263
Definition: except.hxx:391
Definition: except.hxx:279
We can&#39;t tell whether our last statement succeeded.
Definition: except.hxx:148
Definition: except.hxx:252
Definition: except.hxx:438
unexpected_rows(std::string const &msg)
Definition: except.hxx:210
Exception class for failed queries.
Definition: except.hxx:87
Definition: except.hxx:327
Value conversion failed, e.g. when converting "Hello" to int.
Definition: except.hxx:187
Run-time failure encountered by libpqxx, similar to std::runtime_error.
Definition: except.hxx:43
Resource shortage on the server.
Definition: except.hxx:364
Definition: except.hxx:297
Internal error in libpqxx library.
Definition: except.hxx:166
Transaction failed to serialize. Please retry it.
Definition: except.hxx:139
unique_violation(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:272
plpgsql_too_many_rows(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:431
check_violation(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:281
invalid_cursor_name(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:308
Error in data provided to SQL statement.
Definition: except.hxx:225
Exception raised in PL/pgSQL procedure.
Definition: except.hxx:411