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