libpqxx  7.0.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-2020, 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},
315  error_position{pos}
316  {}
317 };
318 
319 struct PQXX_LIBEXPORT undefined_column : syntax_error
320 {
322  std::string const &err, std::string const &Q = "",
323  char const sqlstate[] = nullptr) :
324  syntax_error{err, Q, sqlstate}
325  {}
326 };
327 
328 struct PQXX_LIBEXPORT undefined_function : syntax_error
329 {
331  std::string const &err, std::string const &Q = "",
332  char const sqlstate[] = nullptr) :
333  syntax_error{err, Q, sqlstate}
334  {}
335 };
336 
337 struct PQXX_LIBEXPORT undefined_table : syntax_error
338 {
339  explicit undefined_table(
340  std::string const &err, std::string const &Q = "",
341  char const sqlstate[] = nullptr) :
342  syntax_error{err, Q, sqlstate}
343  {}
344 };
345 
346 struct PQXX_LIBEXPORT insufficient_privilege : sql_error
347 {
349  std::string const &err, std::string const &Q = "",
350  char const sqlstate[] = nullptr) :
351  sql_error{err, Q, sqlstate}
352  {}
353 };
354 
356 struct PQXX_LIBEXPORT insufficient_resources : sql_error
357 {
359  std::string const &err, std::string const &Q = "",
360  char const sqlstate[] = nullptr) :
361  sql_error{err, Q, sqlstate}
362  {}
363 };
364 
365 struct PQXX_LIBEXPORT disk_full : insufficient_resources
366 {
367  explicit disk_full(
368  std::string const &err, std::string const &Q = "",
369  char const sqlstate[] = nullptr) :
370  insufficient_resources{err, Q, sqlstate}
371  {}
372 };
373 
374 struct PQXX_LIBEXPORT out_of_memory : insufficient_resources
375 {
376  explicit out_of_memory(
377  std::string const &err, std::string const &Q = "",
378  char const sqlstate[] = nullptr) :
379  insufficient_resources{err, Q, sqlstate}
380  {}
381 };
382 
384 {
385  explicit too_many_connections(std::string const &err) :
386  broken_connection{err}
387  {}
388 };
389 
391 
393 struct PQXX_LIBEXPORT plpgsql_error : sql_error
394 {
395  explicit plpgsql_error(
396  std::string const &err, std::string const &Q = "",
397  char const sqlstate[] = nullptr) :
398  sql_error{err, Q, sqlstate}
399  {}
400 };
401 
403 struct PQXX_LIBEXPORT plpgsql_raise : plpgsql_error
404 {
405  explicit plpgsql_raise(
406  std::string const &err, std::string const &Q = "",
407  char const sqlstate[] = nullptr) :
408  plpgsql_error{err, Q, sqlstate}
409  {}
410 };
411 
412 struct PQXX_LIBEXPORT plpgsql_no_data_found : plpgsql_error
413 {
415  std::string const &err, std::string const &Q = "",
416  char const sqlstate[] = nullptr) :
417  plpgsql_error{err, Q, sqlstate}
418  {}
419 };
420 
421 struct PQXX_LIBEXPORT plpgsql_too_many_rows : plpgsql_error
422 {
424  std::string const &err, std::string const &Q = "",
425  char const sqlstate[] = nullptr) :
426  plpgsql_error{err, Q, sqlstate}
427  {}
428 };
429 
433 } // namespace pqxx
434 
435 #include "pqxx/internal/compiler-internal-post.hxx"
436 #endif
undefined_table(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:339
plpgsql_error(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:395
insufficient_resources(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:358
Something is out of range, similar to std::out_of_range.
Definition: except.hxx:192
Definition: except.hxx:421
Database feature not supported in current setup.
Definition: except.hxx:206
check_violation(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:272
Definition: except.hxx:252
syntax_error(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr, int pos=-1)
Definition: except.hxx:311
invalid_cursor_state(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:281
Run-time failure encountered by libpqxx, similar to std::runtime_error.
Definition: except.hxx:42
Definition: except.hxx:297
foreign_key_violation(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:254
undefined_column(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:321
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:25
Definition: except.hxx:225
Transaction failed to serialize. Please retry it.
Definition: except.hxx:130
Definition: except.hxx:346
int const error_position
Approximate position in string where error occurred, or -1 if unknown.
Definition: except.hxx:309
Definition: except.hxx:270
Invalid argument passed to libpqxx, similar to std::invalid_argument.
Definition: except.hxx:171
PL/pgSQL error.
Definition: except.hxx:393
Definition: except.hxx:243
Error in data provided to SQL statement.
Definition: except.hxx:216
data_exception(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:218
invalid_cursor_name(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:299
Exception class for failed queries.
Definition: except.hxx:78
Definition: except.hxx:319
Definition: except.hxx:288
Definition: except.hxx:261
disk_full(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:367
Definition: except.hxx:234
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
plpgsql_raise(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:405
Definition: except.hxx:365
restrict_violation(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:236
The backend saw itself forced to roll back the ongoing transaction.
Definition: except.hxx:113
Definition: except.hxx:337
invalid_sql_statement_name(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:290
Exception class for lost or failed backend connection.
Definition: except.hxx:67
Definition: except.hxx:306
Definition: except.hxx:279
plpgsql_no_data_found(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:414
Could not convert value to string: not enough buffer space.
Definition: except.hxx:185
Definition: except.hxx:412
Error in usage of libpqxx library, similar to std::logic_error.
Definition: except.hxx:164
unexpected_rows(std::string const &msg)
Definition: except.hxx:201
Definition: except.hxx:383
plpgsql_too_many_rows(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:423
integrity_constraint_violation(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:227
We can&#39;t tell whether our last statement succeeded.
Definition: except.hxx:139
Resource shortage on the server.
Definition: except.hxx:356
insufficient_privilege(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:348
"Help, I don&#39;t know whether transaction was committed successfully!"
Definition: except.hxx:106
undefined_function(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:330
Definition: except.hxx:328
Query returned an unexpected number of rows.
Definition: except.hxx:199
out_of_memory(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:376
too_many_connections(std::string const &err)
Definition: except.hxx:385
unique_violation(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:263
feature_not_supported(std::string const &err, std::string const &Q="", char const sqlstate[]=nullptr)
Definition: except.hxx:208
Value conversion failed, e.g. when converting "Hello" to int.
Definition: except.hxx:178
Exception raised in PL/pgSQL procedure.
Definition: except.hxx:403
Internal error in libpqxx library.
Definition: except.hxx:157
Definition: except.hxx:374