libpqxx  5.0
except.hxx
1 /*-------------------------------------------------------------------------
2  *
3  * FILE
4  * pqxx/except.hxx
5  *
6  * DESCRIPTION
7  * definition of libpqxx exception classes
8  * pqxx::sql_error, pqxx::broken_connection, pqxx::in_doubt_error, ...
9  * DO NOT INCLUDE THIS FILE DIRECTLY; include pqxx/except instead.
10  *
11  * Copyright (c) 2003-2016, Jeroen T. Vermeulen <jtv@xs4all.nl>
12  *
13  * See COPYING for copyright license. If you did not receive a file called
14  * COPYING with this source code, please notify the distributor of this mistake,
15  * or contact the author.
16  *
17  *-------------------------------------------------------------------------
18  */
19 #ifndef PQXX_H_EXCEPT
20 #define PQXX_H_EXCEPT
21 
22 #include "pqxx/compiler-public.hxx"
23 #include "pqxx/compiler-internal-pre.hxx"
24 
25 #include <stdexcept>
26 
27 #include "pqxx/util"
28 
29 
30 namespace pqxx
31 {
32 
49 
61 class PQXX_LIBEXPORT PQXX_NOVTABLE pqxx_exception
62 {
63 public:
65  virtual ~pqxx_exception() PQXX_NOEXCEPT =0;
66 
68 
90  PQXX_CONST virtual const std::exception &base() //[t0]
91  const PQXX_NOEXCEPT =0;
92 };
93 
94 
96 class PQXX_LIBEXPORT failure :
97  public pqxx_exception, public std::runtime_error
98 {
99  virtual const std::exception &base() const PQXX_NOEXCEPT PQXX_OVERRIDE
100  { return *this; }
101 public:
102  explicit failure(const std::string &);
103 };
104 
105 
107 
125 class PQXX_LIBEXPORT broken_connection : public failure
126 {
127 public:
129  explicit broken_connection(const std::string &);
130 };
131 
132 
134 
137 class PQXX_LIBEXPORT sql_error : public failure
138 {
140  const std::string m_Q;
142  const std::string m_sqlstate;
143 
144 public:
145  explicit sql_error(
146  const std::string &msg="",
147  const std::string &Q="",
148  const char sqlstate[]=NULL);
149  virtual ~sql_error() PQXX_NOEXCEPT;
150 
152  PQXX_PURE const std::string &query() const PQXX_NOEXCEPT; //[t56]
153  PQXX_PURE const std::string &sqlstate() const PQXX_NOEXCEPT;
154 };
155 
156 
157 // TODO: should this be called statement_completion_unknown!?
159 
165 class PQXX_LIBEXPORT in_doubt_error : public failure
166 {
167 public:
168  explicit in_doubt_error(const std::string &);
169 };
170 
171 
173 class PQXX_LIBEXPORT internal_error :
174  public pqxx_exception, public std::logic_error
175 {
176  virtual const std::exception &base() const PQXX_NOEXCEPT PQXX_OVERRIDE
177  { return *this; }
178 public:
179  explicit internal_error(const std::string &);
180 };
181 
182 
184 class PQXX_LIBEXPORT usage_error :
185  public pqxx_exception, public std::logic_error
186 {
187  virtual const std::exception &base() const PQXX_NOEXCEPT PQXX_OVERRIDE
188  { return *this; }
189 public:
190  explicit usage_error(const std::string &);
191 };
192 
193 
195 class PQXX_LIBEXPORT argument_error :
196  public pqxx_exception, public std::invalid_argument
197 {
198  virtual const std::exception &base() const PQXX_NOEXCEPT PQXX_OVERRIDE
199  { return *this; }
200 public:
201  explicit argument_error(const std::string &);
202 };
203 
204 
206 class PQXX_LIBEXPORT conversion_error :
207  public pqxx_exception, public std::domain_error
208 {
209  virtual const std::exception &base() const PQXX_NOEXCEPT PQXX_OVERRIDE
210  { return *this; }
211 public:
212  explicit conversion_error(const std::string &);
213 };
214 
215 
217 class PQXX_LIBEXPORT range_error :
218  public pqxx_exception, public std::out_of_range
219 {
220  virtual const std::exception &base() const PQXX_NOEXCEPT PQXX_OVERRIDE
221  { return *this; }
222 public:
223  explicit range_error(const std::string &);
224 };
225 
226 
228 class PQXX_LIBEXPORT feature_not_supported : public sql_error
229 {
230 public:
232  const std::string &err,
233  const std::string &Q="",
234  const char sqlstate[]=NULL) :
235  sql_error(err, Q, sqlstate) {}
236 };
237 
239 class PQXX_LIBEXPORT data_exception : public sql_error
240 {
241 public:
242  explicit data_exception(
243  const std::string &err,
244  const std::string &Q="",
245  const char sqlstate[]=NULL) :
246  sql_error(err, Q, sqlstate) {}
247 };
248 
249 class PQXX_LIBEXPORT integrity_constraint_violation : public sql_error
250 {
251 public:
253  const std::string &err,
254  const std::string &Q="",
255  const char sqlstate[]=NULL) :
256  sql_error(err, Q, sqlstate) {}
257 };
258 
259 class PQXX_LIBEXPORT restrict_violation :
261 {
262 public:
263  explicit restrict_violation(const std::string &err,
264  const std::string &Q="",
265  const char sqlstate[]=NULL) :
266  integrity_constraint_violation(err, Q, sqlstate) {}
267 };
268 
269 class PQXX_LIBEXPORT not_null_violation :
271 {
272 public:
273  explicit not_null_violation(const std::string &err,
274  const std::string &Q="",
275  const char sqlstate[]=NULL) :
276  integrity_constraint_violation(err, Q, sqlstate) {}
277 };
278 
279 class PQXX_LIBEXPORT foreign_key_violation :
281 {
282 public:
284  const std::string &err,
285  const std::string &Q="",
286  const char sqlstate[]=NULL) :
287  integrity_constraint_violation(err, Q, sqlstate) {}
288 };
289 
290 class PQXX_LIBEXPORT unique_violation :
292 {
293 public:
295  const std::string &err,
296  const std::string &Q="",
297  const char sqlstate[]=NULL) :
298  integrity_constraint_violation(err, Q, sqlstate) {}
299 };
300 
301 class PQXX_LIBEXPORT check_violation :
303 {
304 public:
305  explicit check_violation(
306  const std::string &err,
307  const std::string &Q="",
308  const char sqlstate[]=NULL) :
309  integrity_constraint_violation(err, Q, sqlstate) {}
310 };
311 
312 class PQXX_LIBEXPORT invalid_cursor_state : public sql_error
313 {
314 public:
316  const std::string &err,
317  const std::string &Q="",
318  const char sqlstate[]=NULL) :
319  sql_error(err, Q, sqlstate) {}
320 };
321 
322 class PQXX_LIBEXPORT invalid_sql_statement_name : public sql_error
323 {
324 public:
326  const std::string &err,
327  const std::string &Q="",
328  const char sqlstate[]=NULL) :
329  sql_error(err, Q, sqlstate) {}
330 };
331 
332 class PQXX_LIBEXPORT invalid_cursor_name : public sql_error
333 {
334 public:
336  const std::string &err,
337  const std::string &Q="",
338  const char sqlstate[]=NULL) :
339  sql_error(err, Q, sqlstate) {}
340 };
341 
342 class PQXX_LIBEXPORT syntax_error : public sql_error
343 {
344 public:
346  const int error_position;
347 
348  explicit syntax_error(
349  const std::string &err,
350  const std::string &Q="",
351  const char sqlstate[]=NULL,
352  int pos=-1) :
353  sql_error(err, Q, sqlstate), error_position(pos) {}
354 };
355 
356 class PQXX_LIBEXPORT undefined_column : public syntax_error
357 {
358 public:
360  const std::string &err,
361  const std::string &Q="",
362  const char sqlstate[]=NULL) :
363  syntax_error(err, Q, sqlstate) {}
364 };
365 
366 class PQXX_LIBEXPORT undefined_function : public syntax_error
367 {
368 public:
370  const std::string &err,
371  const std::string &Q="",
372  const char sqlstate[]=NULL) :
373  syntax_error(err, Q, sqlstate) {}
374 };
375 
376 class PQXX_LIBEXPORT undefined_table : public syntax_error
377 {
378 public:
379  explicit undefined_table(
380  const std::string &err,
381  const std::string &Q="",
382  const char sqlstate[]=NULL) :
383  syntax_error(err, Q, sqlstate) {}
384 };
385 
386 class PQXX_LIBEXPORT insufficient_privilege : public sql_error
387 {
388 public:
390  const std::string &err,
391  const std::string &Q="",
392  const char sqlstate[]=NULL) :
393  sql_error(err, Q, sqlstate) {}
394 };
395 
397 class PQXX_LIBEXPORT insufficient_resources : public sql_error
398 {
399 public:
401  const std::string &err,
402  const std::string &Q="",
403  const char sqlstate[]=NULL) :
404  sql_error(err,Q) {}
405 };
406 
407 class PQXX_LIBEXPORT disk_full : public insufficient_resources
408 {
409 public:
410  explicit disk_full(
411  const std::string &err,
412  const std::string &Q="",
413  const char sqlstate[]=NULL) :
414  insufficient_resources(err, Q, sqlstate) {}
415 };
416 
417 class PQXX_LIBEXPORT out_of_memory : public insufficient_resources
418 {
419 public:
420  explicit out_of_memory(
421  const std::string &err,
422  const std::string &Q="",
423  const char sqlstate[]=NULL) :
424  insufficient_resources(err, Q, sqlstate) {}
425 };
426 
427 class PQXX_LIBEXPORT too_many_connections : public broken_connection
428 {
429 public:
430  explicit too_many_connections(const std::string &err) :
431  broken_connection(err) {}
432 };
433 
435 
437 class PQXX_LIBEXPORT plpgsql_error : public sql_error
438 {
439 public:
440  explicit plpgsql_error(
441  const std::string &err,
442  const std::string &Q="",
443  const char sqlstate[]=NULL) :
444  sql_error(err, Q, sqlstate) {}
445 };
446 
448 class PQXX_LIBEXPORT plpgsql_raise : public plpgsql_error
449 {
450 public:
451  explicit plpgsql_raise(
452  const std::string &err,
453  const std::string &Q="",
454  const char sqlstate[]=NULL) :
455  plpgsql_error(err, Q, sqlstate) {}
456 };
457 
458 class PQXX_LIBEXPORT plpgsql_no_data_found : public plpgsql_error
459 {
460 public:
462  const std::string &err,
463  const std::string &Q="",
464  const char sqlstate[]=NULL) :
465  plpgsql_error(err, Q, sqlstate) {}
466 };
467 
468 class PQXX_LIBEXPORT plpgsql_too_many_rows : public plpgsql_error
469 {
470 public:
472  const std::string &err,
473  const std::string &Q="",
474  const char sqlstate[]=NULL) :
475  plpgsql_error(err, Q, sqlstate) {}
476 };
477 
482 }
483 
484 #include "pqxx/compiler-internal-post.hxx"
485 
486 #endif
487 
undefined_column(const std::string &err, const std::string &Q="", const char sqlstate[]=NULL)
Definition: except.hxx:359
out_of_memory(const std::string &err, const std::string &Q="", const char sqlstate[]=NULL)
Definition: except.hxx:420
Error in usage of libpqxx library, similar to std::logic_error.
Definition: except.hxx:184
Definition: except.hxx:458
Run-time failure encountered by libpqxx, similar to std::runtime_error.
Definition: except.hxx:96
invalid_cursor_name(const std::string &err, const std::string &Q="", const char sqlstate[]=NULL)
Definition: except.hxx:335
undefined_function(const std::string &err, const std::string &Q="", const char sqlstate[]=NULL)
Definition: except.hxx:369
Value conversion failed, e.g. when converting &quot;Hello&quot; to int.
Definition: except.hxx:206
plpgsql_error(const std::string &err, const std::string &Q="", const char sqlstate[]=NULL)
Definition: except.hxx:440
insufficient_resources(const std::string &err, const std::string &Q="", const char sqlstate[]=NULL)
Definition: except.hxx:400
Definition: except.hxx:386
check_violation(const std::string &err, const std::string &Q="", const char sqlstate[]=NULL)
Definition: except.hxx:305
Definition: except.hxx:417
Definition: except.hxx:269
plpgsql_raise(const std::string &err, const std::string &Q="", const char sqlstate[]=NULL)
Definition: except.hxx:451
Internal error in libpqxx library.
Definition: except.hxx:173
const int error_position
Approximate position in string where error occurred, or -1 if unknown.
Definition: except.hxx:346
Definition: except.hxx:259
PL/pgSQL error.
Definition: except.hxx:437
Exception class for failed queries.
Definition: except.hxx:137
insufficient_privilege(const std::string &err, const std::string &Q="", const char sqlstate[]=NULL)
Definition: except.hxx:389
Definition: except.hxx:279
Exception class for lost or failed backend connection.
Definition: except.hxx:125
Definition: except.hxx:468
integrity_constraint_violation(const std::string &err, const std::string &Q="", const char sqlstate[]=NULL)
Definition: except.hxx:252
invalid_sql_statement_name(const std::string &err, const std::string &Q="", const char sqlstate[]=NULL)
Definition: except.hxx:325
Definition: except.hxx:366
not_null_violation(const std::string &err, const std::string &Q="", const char sqlstate[]=NULL)
Definition: except.hxx:273
undefined_table(const std::string &err, const std::string &Q="", const char sqlstate[]=NULL)
Definition: except.hxx:379
Something is out of range, similar to std::out_of_range.
Definition: except.hxx:217
Definition: except.hxx:290
plpgsql_no_data_found(const std::string &err, const std::string &Q="", const char sqlstate[]=NULL)
Definition: except.hxx:461
Definition: except.hxx:342
feature_not_supported(const std::string &err, const std::string &Q="", const char sqlstate[]=NULL)
Definition: except.hxx:231
Definition: except.hxx:427
&quot;Help, I don&#39;t know whether transaction was committed successfully!&quot;
Definition: except.hxx:165
data_exception(const std::string &err, const std::string &Q="", const char sqlstate[]=NULL)
Definition: except.hxx:242
Definition: except.hxx:356
Error in data provided to SQL statement.
Definition: except.hxx:239
plpgsql_too_many_rows(const std::string &err, const std::string &Q="", const char sqlstate[]=NULL)
Definition: except.hxx:471
Definition: except.hxx:249
syntax_error(const std::string &err, const std::string &Q="", const char sqlstate[]=NULL, int pos=-1)
Definition: except.hxx:348
Definition: except.hxx:312
Database feature not supported in current setup.
Definition: except.hxx:228
foreign_key_violation(const std::string &err, const std::string &Q="", const char sqlstate[]=NULL)
Definition: except.hxx:283
Exception raised in PL/pgSQL procedure.
Definition: except.hxx:448
Mixin base class to identify libpqxx-specific exception types.
Definition: except.hxx:61
Invalid argument passed to libpqxx, similar to std::invalid_argument.
Definition: except.hxx:195
invalid_cursor_state(const std::string &err, const std::string &Q="", const char sqlstate[]=NULL)
Definition: except.hxx:315
too_many_connections(const std::string &err)
Definition: except.hxx:430
unique_violation(const std::string &err, const std::string &Q="", const char sqlstate[]=NULL)
Definition: except.hxx:294
Definition: except.hxx:322
Definition: except.hxx:332
restrict_violation(const std::string &err, const std::string &Q="", const char sqlstate[]=NULL)
Definition: except.hxx:263
disk_full(const std::string &err, const std::string &Q="", const char sqlstate[]=NULL)
Definition: except.hxx:410
Resource shortage on the server.
Definition: except.hxx:397
Definition: except.hxx:301
Definition: except.hxx:407
Definition: except.hxx:376