error.hpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. //
  2. // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // Official repository: https://github.com/boostorg/json
  8. //
  9. #ifndef BOOST_JSON_ERROR_HPP
  10. #define BOOST_JSON_ERROR_HPP
  11. #include <boost/json/detail/config.hpp>
  12. #ifndef BOOST_JSON_STANDALONE
  13. # include <boost/system/error_code.hpp>
  14. # include <boost/system/system_error.hpp>
  15. #else
  16. # include <system_error>
  17. #endif
  18. BOOST_JSON_NS_BEGIN
  19. #ifdef BOOST_JSON_DOCS
  20. /** The type of error code used by the library.
  21. This type alias is set depending
  22. on how the library is configured:
  23. @par Use with Boost
  24. If the macro `BOOST_JSON_STANDALONE` is
  25. not defined, this type will be an alias
  26. for `boost::system::error_code`.
  27. Compiling a program using the library will
  28. require Boost, and a compiler conforming
  29. to C++11 or later.
  30. @par Use without Boost
  31. If the macro `BOOST_JSON_STANDALONE` is
  32. defined, this type will be an alias
  33. for `std::error_code`.
  34. Compiling a program using the library will
  35. require only a compiler conforming to C++17
  36. or later.
  37. @see https://en.cppreference.com/w/cpp/error/error_code
  38. */
  39. using error_code = __see_below__;
  40. /** The type of error category used by the library.
  41. This type alias is set depending
  42. on how the library is configured:
  43. @par Use with Boost
  44. If the macro `BOOST_JSON_STANDALONE` is
  45. not defined, this type will be an alias
  46. for `boost::system::error_category`.
  47. Compiling a program using the library will
  48. require Boost, and a compiler conforming
  49. to C++11 or later.
  50. @par Use without Boost
  51. If the macro `BOOST_JSON_STANDALONE` is
  52. defined, this type will be an alias
  53. for `std::error_category`.
  54. Compiling a program using the library will
  55. require only a compiler conforming to C++17
  56. or later.
  57. @see https://en.cppreference.com/w/cpp/error/error_category
  58. */
  59. using error_category = __see_below__;
  60. /** The type of error condition used by the library.
  61. This type alias is set depending
  62. on how the library is configured:
  63. @par Use with Boost
  64. If the macro `BOOST_JSON_STANDALONE` is
  65. not defined, this type will be an alias
  66. for `boost::system::error_condition`.
  67. Compiling a program using the library will
  68. require Boost, and a compiler conforming
  69. to C++11 or later.
  70. @par Use without Boost
  71. If the macro `BOOST_JSON_STANDALONE` is
  72. defined, this type will be an alias
  73. for `std::error_condition`.
  74. Compiling a program using the library will
  75. require only a compiler conforming to C++17
  76. or later.
  77. @see https://en.cppreference.com/w/cpp/error/error_condition
  78. */
  79. using error_condition = __see_below__;
  80. /** The type of system error thrown by the library.
  81. This type alias is set depending
  82. on how the library is configured:
  83. @par Use with Boost
  84. If the macro `BOOST_JSON_STANDALONE` is
  85. not defined, this type will be an alias
  86. for `boost::system::system_error`.
  87. Compiling a program using the library will
  88. require Boost, and a compiler conforming
  89. to C++11 or later.
  90. @par Use without Boost
  91. If the macro `BOOST_JSON_STANDALONE` is
  92. defined, this type will be an alias
  93. for `std::system_error`.
  94. Compiling a program using the library will
  95. require only a compiler conforming to C++17
  96. or later.
  97. @see https://en.cppreference.com/w/cpp/error/system_error
  98. */
  99. using system_error = __see_below__;
  100. /// Returns the generic error category used by the library.
  101. error_category const&
  102. generic_category();
  103. #elif ! defined(BOOST_JSON_STANDALONE)
  104. using error_code = boost::system::error_code;
  105. using error_category = boost::system::error_category;
  106. using error_condition = boost::system::error_condition;
  107. using system_error = boost::system::system_error;
  108. using boost::system::generic_category;
  109. #else
  110. using error_code = std::error_code;
  111. using error_category = std::error_category;
  112. using error_condition = std::error_condition;
  113. using system_error = std::system_error;
  114. using std::generic_category;
  115. #endif
  116. /** Error codes returned by JSON operations
  117. */
  118. enum class error
  119. {
  120. //
  121. // parse errors
  122. //
  123. /// syntax error
  124. syntax = 1,
  125. /// extra data
  126. extra_data,
  127. /// incomplete JSON
  128. incomplete,
  129. /// exponent too large
  130. exponent_overflow,
  131. /// too deep
  132. too_deep,
  133. /// illegal leading surrogate
  134. illegal_leading_surrogate,
  135. /// illegal trailing surrogate
  136. illegal_trailing_surrogate,
  137. /// expected hex digit
  138. expected_hex_digit,
  139. /// expected utf16 escape
  140. expected_utf16_escape,
  141. /// An object contains too many elements
  142. object_too_large,
  143. /// An array contains too many elements
  144. array_too_large,
  145. /// A key is too large
  146. key_too_large,
  147. /// A string is too large
  148. string_too_large,
  149. /// The parser encountered an exception and must be reset
  150. exception,
  151. //----------------------------------
  152. /// not a number
  153. not_number,
  154. /// number cast is not exact
  155. not_exact,
  156. /// test failure
  157. test_failure,
  158. };
  159. /** Error conditions corresponding to JSON errors
  160. */
  161. enum class condition
  162. {
  163. /// A parser-related error
  164. parse_error = 1,
  165. /// An error on assignment to or from a JSON value
  166. assign_error
  167. };
  168. BOOST_JSON_NS_END
  169. #include <boost/json/impl/error.hpp>
  170. #endif