errors.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (C) 2010-2011 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
  4. //
  5. // Distributed under:
  6. //
  7. // the Boost Software License, Version 1.0.
  8. // (See accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. //
  11. // or (at your opinion) under:
  12. //
  13. // The MIT License
  14. // (See accompanying file MIT.txt or a copy at
  15. // http://www.opensource.org/licenses/mit-license.php)
  16. //
  17. ///////////////////////////////////////////////////////////////////////////////
  18. #ifndef CPPDB_ERRORS_H
  19. #define CPPDB_ERRORS_H
  20. #include <stdexcept>
  21. #include <string>
  22. namespace cppdb {
  23. ///
  24. /// \brief This is the base error of all errors thrown by cppdb.
  25. ///
  26. class cppdb_error : public std::runtime_error {
  27. public:
  28. ///
  29. /// Create a cppdb_error with error message \a v
  30. ///
  31. cppdb_error(std::string const &v) : std::runtime_error(v) {}
  32. };
  33. ///
  34. /// \brief invalid data conversions
  35. ///
  36. /// It may be thrown if the data can't be converted to required format, for example trying to fetch
  37. /// a negative value with unsigned type or parsing invalid string as datatime.
  38. ///
  39. class bad_value_cast : public cppdb_error {
  40. public:
  41. bad_value_cast() : cppdb_error("cppdb::bad_value_cast can't convert data")
  42. {
  43. }
  44. };
  45. ///
  46. /// \brief attempt to fetch a null value.
  47. ///
  48. /// Thrown by cppdb::result::get functions.
  49. ///
  50. class null_value_fetch : public cppdb_error {
  51. public:
  52. null_value_fetch() : cppdb_error("cppdb::null_value_fetch attempt fetch null column")
  53. {
  54. }
  55. };
  56. ///
  57. /// \brief attempt to fetch a value from the row without calling next() first time or when next() returned false.
  58. ///
  59. class empty_row_access : public cppdb_error {
  60. public:
  61. empty_row_access() : cppdb_error("cppdb::empty_row_access attempt to fetch from empty column")
  62. {
  63. }
  64. };
  65. ///
  66. /// \brief trying to fetch a value using invalid column index
  67. ///
  68. class invalid_column : public cppdb_error {
  69. public:
  70. invalid_column() : cppdb_error("cppdb::invalid_column attempt access to invalid column")
  71. {
  72. }
  73. };
  74. ///
  75. /// \brief trying to fetch a value using invalid placeholder
  76. ///
  77. class invalid_placeholder : public cppdb_error {
  78. public:
  79. invalid_placeholder() : cppdb_error("cppdb::invalid_placeholder attempt bind to invalid placeholder")
  80. {
  81. }
  82. };
  83. ///
  84. /// \brief trying to fetch a single row for a query that returned multiple ones.
  85. ///
  86. class multiple_rows_query : public cppdb_error {
  87. public:
  88. multiple_rows_query() : cppdb_error( "cppdb::multiple_rows_query "
  89. "multiple rows result for a single row request")
  90. {
  91. }
  92. };
  93. ///
  94. /// \brief This operation is not supported by the backend
  95. ///
  96. class not_supported_by_backend : public cppdb_error {
  97. public:
  98. ///
  99. /// Create a not_supported_by_backend with error message \a e
  100. ///
  101. not_supported_by_backend(std::string const &e) :
  102. cppdb_error(e)
  103. {
  104. }
  105. };
  106. }
  107. #endif