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