libpqxx
except.hxx
1
13#ifndef PQXX_H_EXCEPT
14#define PQXX_H_EXCEPT
15
16#include "pqxx/compiler-public.hxx"
17#include "pqxx/compiler-internal-pre.hxx"
18
19#include <stdexcept>
20
21#include "pqxx/util.hxx"
22
23
24namespace pqxx
25{
26
44
55class PQXX_LIBEXPORT PQXX_NOVTABLE pqxx_exception
56{
57public:
59 virtual ~pqxx_exception() noexcept =0;
60
62
84 PQXX_CONST virtual const std::exception &base() const noexcept =0; //[t00]
85};
86
87
89class PQXX_LIBEXPORT failure :
90 public pqxx_exception, public std::runtime_error
91{
92 virtual const std::exception &base() const noexcept override
93 { return *this; }
94public:
95 explicit failure(const std::string &);
96};
97
98
100
118class PQXX_LIBEXPORT broken_connection : public failure
119{
120public:
122 explicit broken_connection(const std::string &);
123};
124
125
127
130class PQXX_LIBEXPORT sql_error : public failure
131{
133 const std::string m_query;
135 const std::string m_sqlstate;
136
137public:
138 explicit sql_error(
139 const std::string &msg="",
140 const std::string &Q="",
141 const char sqlstate[]=nullptr);
142 virtual ~sql_error() noexcept;
143
145 PQXX_PURE const std::string &query() const noexcept; //[t56]
146
148 PQXX_PURE const std::string &sqlstate() const noexcept;
149};
150
151
153
159class PQXX_LIBEXPORT in_doubt_error : public failure
160{
161public:
162 explicit in_doubt_error(const std::string &);
163};
164
165
167class PQXX_LIBEXPORT transaction_rollback : public failure
168{
169public:
170 explicit transaction_rollback(const std::string &);
171};
172
173
175
183class PQXX_LIBEXPORT serialization_failure : public transaction_rollback
184{
185public:
186 explicit serialization_failure(const std::string &);
187};
188
189
192{
193public:
194 explicit statement_completion_unknown(const std::string &);
195};
196
197
199class PQXX_LIBEXPORT deadlock_detected : public transaction_rollback
200{
201public:
202 explicit deadlock_detected(const std::string &);
203};
204
205
207class PQXX_LIBEXPORT internal_error :
208 public pqxx_exception, public std::logic_error
209{
210 virtual const std::exception &base() const noexcept override
211 { return *this; }
212public:
213 explicit internal_error(const std::string &);
214};
215
216
218class PQXX_LIBEXPORT usage_error :
219 public pqxx_exception, public std::logic_error
220{
221 virtual const std::exception &base() const noexcept override
222 { return *this; }
223public:
224 explicit usage_error(const std::string &);
225};
226
227
229class PQXX_LIBEXPORT argument_error :
230 public pqxx_exception, public std::invalid_argument
231{
232 virtual const std::exception &base() const noexcept override
233 { return *this; }
234public:
235 explicit argument_error(const std::string &);
236};
237
238
240class PQXX_LIBEXPORT conversion_error :
241 public pqxx_exception, public std::domain_error
242{
243 virtual const std::exception &base() const noexcept override
244 { return *this; }
245public:
246 explicit conversion_error(const std::string &);
247};
248
249
251class PQXX_LIBEXPORT range_error :
252 public pqxx_exception, public std::out_of_range
253{
254 virtual const std::exception &base() const noexcept override
255 { return *this; }
256public:
257 explicit range_error(const std::string &);
258};
259
260
262class PQXX_LIBEXPORT unexpected_rows : public range_error
263{
264 virtual const std::exception &base() const noexcept override
265 { return *this; }
266public:
267 explicit unexpected_rows(const std::string &msg) : range_error{msg} {}
268};
269
270
272class PQXX_LIBEXPORT feature_not_supported : public sql_error
273{
274public:
276 const std::string &err,
277 const std::string &Q="",
278 const char sqlstate[]=nullptr) :
279 sql_error{err, Q, sqlstate} {}
280};
281
283class PQXX_LIBEXPORT data_exception : public sql_error
284{
285public:
287 const std::string &err,
288 const std::string &Q="",
289 const char sqlstate[]=nullptr) :
290 sql_error{err, Q, sqlstate} {}
291};
292
293class PQXX_LIBEXPORT integrity_constraint_violation : public sql_error
294{
295public:
297 const std::string &err,
298 const std::string &Q="",
299 const char sqlstate[]=nullptr) :
300 sql_error{err, Q, sqlstate} {}
301};
302
303class PQXX_LIBEXPORT restrict_violation :
305{
306public:
308 const std::string &err,
309 const std::string &Q="",
310 const char sqlstate[]=nullptr) :
311 integrity_constraint_violation{err, Q, sqlstate} {}
312};
313
314class PQXX_LIBEXPORT not_null_violation :
316{
317public:
319 const std::string &err,
320 const std::string &Q="",
321 const char sqlstate[]=nullptr) :
322 integrity_constraint_violation{err, Q, sqlstate} {}
323};
324
325class PQXX_LIBEXPORT foreign_key_violation :
327{
328public:
330 const std::string &err,
331 const std::string &Q="",
332 const char sqlstate[]=nullptr) :
333 integrity_constraint_violation{err, Q, sqlstate} {}
334};
335
336class PQXX_LIBEXPORT unique_violation :
338{
339public:
341 const std::string &err,
342 const std::string &Q="",
343 const char sqlstate[]=nullptr) :
344 integrity_constraint_violation{err, Q, sqlstate} {}
345};
346
347class PQXX_LIBEXPORT check_violation :
349{
350public:
352 const std::string &err,
353 const std::string &Q="",
354 const char sqlstate[]=nullptr) :
355 integrity_constraint_violation{err, Q, sqlstate} {}
356};
357
358class PQXX_LIBEXPORT invalid_cursor_state : public sql_error
359{
360public:
362 const std::string &err,
363 const std::string &Q="",
364 const char sqlstate[]=nullptr) :
365 sql_error{err, Q, sqlstate} {}
366};
367
368class PQXX_LIBEXPORT invalid_sql_statement_name : public sql_error
369{
370public:
372 const std::string &err,
373 const std::string &Q="",
374 const char sqlstate[]=nullptr) :
375 sql_error{err, Q, sqlstate} {}
376};
377
378class PQXX_LIBEXPORT invalid_cursor_name : public sql_error
379{
380public:
382 const std::string &err,
383 const std::string &Q="",
384 const char sqlstate[]=nullptr) :
385 sql_error{err, Q, sqlstate} {}
386};
387
388class PQXX_LIBEXPORT syntax_error : public sql_error
389{
390public:
392 const int error_position;
393
394 explicit syntax_error(
395 const std::string &err,
396 const std::string &Q="",
397 const char sqlstate[]=nullptr,
398 int pos=-1) :
399 sql_error{err, Q, sqlstate}, error_position{pos} {}
400};
401
402class PQXX_LIBEXPORT undefined_column : public syntax_error
403{
404public:
406 const std::string &err,
407 const std::string &Q="",
408 const char sqlstate[]=nullptr) :
409 syntax_error{err, Q, sqlstate} {}
410};
411
412class PQXX_LIBEXPORT undefined_function : public syntax_error
413{
414public:
416 const std::string &err,
417 const std::string &Q="",
418 const char sqlstate[]=nullptr) :
419 syntax_error{err, Q, sqlstate} {}
420};
421
422class PQXX_LIBEXPORT undefined_table : public syntax_error
423{
424public:
426 const std::string &err,
427 const std::string &Q="",
428 const char sqlstate[]=nullptr) :
429 syntax_error{err, Q, sqlstate} {}
430};
431
432class PQXX_LIBEXPORT insufficient_privilege : public sql_error
433{
434public:
436 const std::string &err,
437 const std::string &Q="",
438 const char sqlstate[]=nullptr) :
439 sql_error{err, Q, sqlstate} {}
440};
441
443class PQXX_LIBEXPORT insufficient_resources : public sql_error
444{
445public:
447 const std::string &err,
448 const std::string &Q="",
449 const char sqlstate[]=nullptr) :
450 sql_error{err,Q, sqlstate} {}
451};
452
453class PQXX_LIBEXPORT disk_full : public insufficient_resources
454{
455public:
456 explicit disk_full(
457 const std::string &err,
458 const std::string &Q="",
459 const char sqlstate[]=nullptr) :
460 insufficient_resources{err, Q, sqlstate} {}
461};
462
463class PQXX_LIBEXPORT out_of_memory : public insufficient_resources
464{
465public:
467 const std::string &err,
468 const std::string &Q="",
469 const char sqlstate[]=nullptr) :
470 insufficient_resources{err, Q, sqlstate} {}
471};
472
473class PQXX_LIBEXPORT too_many_connections : public broken_connection
474{
475public:
476 explicit too_many_connections(const std::string &err) :
477 broken_connection{err} {}
478};
479
481
483class PQXX_LIBEXPORT plpgsql_error : public sql_error
484{
485public:
487 const std::string &err,
488 const std::string &Q="",
489 const char sqlstate[]=nullptr) :
490 sql_error{err, Q, sqlstate} {}
491};
492
494class PQXX_LIBEXPORT plpgsql_raise : public plpgsql_error
495{
496public:
498 const std::string &err,
499 const std::string &Q="",
500 const char sqlstate[]=nullptr) :
501 plpgsql_error{err, Q, sqlstate} {}
502};
503
504class PQXX_LIBEXPORT plpgsql_no_data_found : public plpgsql_error
505{
506public:
508 const std::string &err,
509 const std::string &Q="",
510 const char sqlstate[]=nullptr) :
511 plpgsql_error{err, Q, sqlstate} {}
512};
513
514class PQXX_LIBEXPORT plpgsql_too_many_rows : public plpgsql_error
515{
516public:
518 const std::string &err,
519 const std::string &Q="",
520 const char sqlstate[]=nullptr) :
521 plpgsql_error{err, Q, sqlstate} {}
522};
523
528}
529
530#include "pqxx/compiler-internal-post.hxx"
531
532#endif
STL namespace.
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:26
Mixin base class to identify libpqxx-specific exception types.
Definition: except.hxx:56
virtual PQXX_CONST const std::exception & base() const noexcept=0
Return std::exception base-class object.
Run-time failure encountered by libpqxx, similar to std::runtime_error.
Definition: except.hxx:91
Exception class for lost or failed backend connection.
Definition: except.hxx:119
Exception class for failed queries.
Definition: except.hxx:131
"Help, I don't know whether transaction was committed successfully!"
Definition: except.hxx:160
The backend saw itself forced to roll back the ongoing transaction.
Definition: except.hxx:168
Transaction failed to serialize. Please retry it.
Definition: except.hxx:184
We can't tell whether our last statement succeeded.
Definition: except.hxx:192
The ongoing transaction has deadlocked. Retrying it may help.
Definition: except.hxx:200
Internal error in libpqxx library.
Definition: except.hxx:209
Error in usage of libpqxx library, similar to std::logic_error.
Definition: except.hxx:220
Invalid argument passed to libpqxx, similar to std::invalid_argument.
Definition: except.hxx:231
Value conversion failed, e.g. when converting "Hello" to int.
Definition: except.hxx:242
Something is out of range, similar to std::out_of_range.
Definition: except.hxx:253
Query returned an unexpected number of rows.
Definition: except.hxx:263
unexpected_rows(const std::string &msg)
Definition: except.hxx:267
Database feature not supported in current setup.
Definition: except.hxx:273
feature_not_supported(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:275
Error in data provided to SQL statement.
Definition: except.hxx:284
data_exception(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:286
Definition: except.hxx:294
integrity_constraint_violation(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:296
Definition: except.hxx:305
restrict_violation(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:307
Definition: except.hxx:316
not_null_violation(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:318
Definition: except.hxx:327
foreign_key_violation(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:329
Definition: except.hxx:338
unique_violation(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:340
Definition: except.hxx:349
check_violation(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:351
Definition: except.hxx:359
invalid_cursor_state(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:361
Definition: except.hxx:369
invalid_sql_statement_name(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:371
Definition: except.hxx:379
invalid_cursor_name(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:381
Definition: except.hxx:389
const int error_position
Approximate position in string where error occurred, or -1 if unknown.
Definition: except.hxx:392
syntax_error(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr, int pos=-1)
Definition: except.hxx:394
Definition: except.hxx:403
undefined_column(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:405
Definition: except.hxx:413
undefined_function(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:415
Definition: except.hxx:423
undefined_table(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:425
Definition: except.hxx:433
insufficient_privilege(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:435
Resource shortage on the server.
Definition: except.hxx:444
insufficient_resources(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:446
Definition: except.hxx:454
disk_full(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:456
Definition: except.hxx:464
out_of_memory(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:466
Definition: except.hxx:474
too_many_connections(const std::string &err)
Definition: except.hxx:476
PL/pgSQL error.
Definition: except.hxx:484
plpgsql_error(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:486
Exception raised in PL/pgSQL procedure.
Definition: except.hxx:495
plpgsql_raise(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:497
Definition: except.hxx:505
plpgsql_no_data_found(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:507
Definition: except.hxx:515
plpgsql_too_many_rows(const std::string &err, const std::string &Q="", const char sqlstate[]=nullptr)
Definition: except.hxx:517