libpqxx  7.4.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-2021, 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 #include "pqxx/compiler-public.hxx"
17 #include "pqxx/internal/compiler-internal-pre.hxx"
18 
19 #include <stdexcept>
20 #include <string>
21 
22 
23 namespace pqxx
24 {
41 struct PQXX_LIBEXPORT failure : std::runtime_error
43 {
44  explicit failure(std::string const &);
45 };
46 
47 
49 
67 struct PQXX_LIBEXPORT broken_connection : failure
68 {
70  explicit broken_connection(std::string const &);
71 };
72 
73 
75 
78 class PQXX_LIBEXPORT sql_error : public failure
79 {
81  std::string const m_query;
83  std::string const m_sqlstate;
84 
85 public:
86  explicit sql_error(
87  std::string const &whatarg = "", std::string const &Q = "",
88  char const sqlstate[] = nullptr);
89  virtual ~sql_error() noexcept override;
90 
92  [[nodiscard]] PQXX_PURE std::string const &query() const noexcept;
93 
95  [[nodiscard]] PQXX_PURE std::string const &sqlstate() const noexcept;
96 };
97 
98 
100 
106 struct PQXX_LIBEXPORT in_doubt_error : failure
107 {
108  explicit in_doubt_error(std::string const &);
109 };
110 
111 
113 struct PQXX_LIBEXPORT transaction_rollback : sql_error
114 {
115  explicit transaction_rollback(
116  std::string const &whatarg, std::string const &q = "",
117  char const sqlstate[] = nullptr);
118 };
119 
120 
122 
131 {
132  explicit serialization_failure(
133  std::string const &whatarg, std::string const &q,
134  char const sqlstate[] = nullptr);
135 };
136 
137 
140 {
142  std::string const &whatarg, std::string const &q,
143  char const sqlstate[] = nullptr);
144 };
145 
146 
149 {
150  explicit deadlock_detected(
151  std::string const &whatarg, std::string const &q,
152  char const sqlstate[] = nullptr);
153 };
154 
155 
157 struct PQXX_LIBEXPORT internal_error : std::logic_error
158 {
159  explicit internal_error(std::string const &);
160 };
161 
162 
164 struct PQXX_LIBEXPORT usage_error : std::logic_error
165 {
166  explicit usage_error(std::string const &);
167 };
168 
169 
171 struct PQXX_LIBEXPORT argument_error : std::invalid_argument
172 {
173  explicit argument_error(std::string const &);
174 };
175 
176 
178 struct PQXX_LIBEXPORT conversion_error : std::domain_error
179 {
180  explicit conversion_error(std::string const &);
181 };
182 
183 
185 struct PQXX_LIBEXPORT conversion_overrun : conversion_error
186 {
187  explicit conversion_overrun(std::string const &);
188 };
189 
190 
192 struct PQXX_LIBEXPORT range_error : std::out_of_range
193 {
194  explicit range_error(std::string const &);
195 };
196 
197 
199 struct PQXX_LIBEXPORT unexpected_rows : public range_error
200 {
201  explicit unexpected_rows(std::string const &msg) : range_error{msg} {}
202 };
203 
204 
206 struct PQXX_LIBEXPORT feature_not_supported : sql_error
207 {
209  std::string const &err, std::string const &Q = "",
210  char const sqlstate[] = nullptr) :
211  sql_error{err, Q, sqlstate}
212  {}
213 };
214 
216 struct PQXX_LIBEXPORT data_exception : sql_error
217 {
218  explicit data_exception(
219  std::string const &err, std::string const &Q = "",
220  char const sqlstate[] = nullptr) :
221  sql_error{err, Q, sqlstate}
222  {}
223 };
224 
226 {
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  integrity_constraint_violation{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 {
272  explicit check_violation(
273  std::string const &err, std::string const &Q = "",
274  char const sqlstate[] = nullptr) :
275  integrity_constraint_violation{err, Q, sqlstate}
276  {}
277 };
278 
279 struct PQXX_LIBEXPORT invalid_cursor_state : sql_error
280 {
282  std::string const &err, std::string const &Q = "",
283  char const sqlstate[] = nullptr) :
284  sql_error{err, Q, sqlstate}
285  {}
286 };
287 
288 struct PQXX_LIBEXPORT invalid_sql_statement_name : 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_cursor_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 syntax_error : sql_error
307 {
309  int const error_position;
310 
311  explicit syntax_error(
312  std::string const &err, std::string const &Q = "",
313  char const sqlstate[] = nullptr, int pos = -1) :
314  sql_error{err, Q, sqlstate}, error_position{pos}
315  {}
316 };
317 
318 struct PQXX_LIBEXPORT undefined_column : syntax_error
319 {
321  std::string const &err, std::string const &Q = "",
322  char const sqlstate[] = nullptr) :
323  syntax_error{err, Q, sqlstate}
324  {}
325 };
326 
327 struct PQXX_LIBEXPORT undefined_function : 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_table : syntax_error
337 {
338  explicit undefined_table(
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 insufficient_privilege : sql_error
346 {
348  std::string const &err, std::string const &Q = "",
349  char const sqlstate[] = nullptr) :
350  sql_error{err, Q, sqlstate}
351  {}
352 };
353 
355 struct PQXX_LIBEXPORT insufficient_resources : sql_error
356 {
358  std::string const &err, std::string const &Q = "",
359  char const sqlstate[] = nullptr) :
360  sql_error{err, Q, sqlstate}
361  {}
362 };
363 
364 struct PQXX_LIBEXPORT disk_full : insufficient_resources
365 {
366  explicit disk_full(
367  std::string const &err, std::string const &Q = "",
368  char const sqlstate[] = nullptr) :
369  insufficient_resources{err, Q, sqlstate}
370  {}
371 };
372 
373 struct PQXX_LIBEXPORT out_of_memory : insufficient_resources
374 {
375  explicit out_of_memory(
376  std::string const &err, std::string const &Q = "",
377  char const sqlstate[] = nullptr) :
378  insufficient_resources{err, Q, sqlstate}
379  {}
380 };
381 
383 {
384  explicit too_many_connections(std::string const &err) :
385  broken_connection{err}
386  {}
387 };
388 
390 
392 struct PQXX_LIBEXPORT plpgsql_error : sql_error
393 {
394  explicit plpgsql_error(
395  std::string const &err, std::string const &Q = "",
396  char const sqlstate[] = nullptr) :
397  sql_error{err, Q, sqlstate}
398  {}
399 };
400 
402 struct PQXX_LIBEXPORT plpgsql_raise : plpgsql_error
403 {
404  explicit plpgsql_raise(
405  std::string const &err, std::string const &Q = "",
406  char const sqlstate[] = nullptr) :
407  plpgsql_error{err, Q, sqlstate}
408  {}
409 };
410 
411 struct PQXX_LIBEXPORT plpgsql_no_data_found : plpgsql_error
412 {
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_too_many_rows : 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 blob_already_exists : failure
430 {
431  explicit blob_already_exists(std::string const &);
432 };
433 
437 } // namespace pqxx
438 
439 #include "pqxx/internal/compiler-internal-post.hxx"
440 #endif
plpgsql_no_data_found(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:413
disk_full(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:366
Query returned an unexpected number of rows.
Definition: except.hxx:199
Definition: except.hxx:382
Value conversion failed, e.g. when converting "Hello" to int.
Definition: except.hxx:178
plpgsql_error(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:394
Definition: except.hxx:243
Definition: except.hxx:429
Error in data provided to SQL statement.
Definition: except.hxx:216
Exception raised in PL/pgSQL procedure.
Definition: except.hxx:402
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:25
undefined_function(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:329
unique_violation(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:263
Definition: except.hxx:288
out_of_memory(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:375
Definition: except.hxx:261
plpgsql_too_many_rows(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:422
unexpected_rows(std::string const &msg)
Definition: except.hxx:201
int const error_position
Approximate position in string where error occurred, or -1 if unknown.
Definition: except.hxx:309
The backend saw itself forced to roll back the ongoing transaction.
Definition: except.hxx:113
invalid_cursor_name(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:299
Definition: except.hxx:336
Something is out of range, similar to std::out_of_range.
Definition: except.hxx:192
Exception class for lost or failed backend connection.
Definition: except.hxx:67
Definition: except.hxx:306
Invalid argument passed to libpqxx, similar to std::invalid_argument.
Definition: except.hxx:171
foreign_key_violation(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:254
restrict_violation(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:236
Definition: except.hxx:234
We can&#39;t tell whether our last statement succeeded.
Definition: except.hxx:139
Definition: except.hxx:420
Resource shortage on the server.
Definition: except.hxx:355
Database feature not supported in current setup.
Definition: except.hxx:206
insufficient_privilege(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:347
PL/pgSQL error.
Definition: except.hxx:392
undefined_column(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:320
Could not convert value to string: not enough buffer space.
Definition: except.hxx:185
Definition: except.hxx:279
Definition: except.hxx:252
Definition: except.hxx:225
Definition: except.hxx:411
"Help, I don&#39;t know whether transaction was committed successfully!"
Definition: except.hxx:106
Definition: except.hxx:327
feature_not_supported(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:208
Run-time failure encountered by libpqxx, similar to std::runtime_error.
Definition: except.hxx:42
syntax_error(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr, int pos=-1)
Definition: except.hxx:311
Definition: except.hxx:297
Definition: except.hxx:270
undefined_table(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:338
plpgsql_raise(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:404
Internal error in libpqxx library.
Definition: except.hxx:157
data_exception(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:218
Definition: except.hxx:373
Transaction failed to serialize. Please retry it.
Definition: except.hxx:130
Definition: except.hxx:345
Exception class for failed queries.
Definition: except.hxx:78
Definition: except.hxx:318
invalid_cursor_state(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:281
not_null_violation(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:245
The ongoing transaction has deadlocked. Retrying it may help.
Definition: except.hxx:148
Definition: except.hxx:364
check_violation(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:272
integrity_constraint_violation(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:227
insufficient_resources(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:357
Error in usage of libpqxx library, similar to std::logic_error.
Definition: except.hxx:164
invalid_sql_statement_name(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:290
too_many_connections(std::string const &err)
Definition: except.hxx:384