json_exception.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // json_exception.h
  3. // json
  4. //
  5. // Created by Sam Jaffe on 11/17/18.
  6. // Copyright © 2018 Sam Jaffe. All rights reserved.
  7. //
  8. #pragma once
  9. #include <stdexcept>
  10. #include <typeinfo>
  11. namespace json {
  12. class malformed_json_exception :
  13. public std::domain_error {
  14. using std::domain_error::domain_error;
  15. };
  16. struct not_an_object_exception :
  17. public malformed_json_exception {
  18. template <typename T>
  19. not_an_object_exception(T const &)
  20. : not_an_object_exception(typeid(T).name()) {}
  21. not_an_object_exception(char const * tname);
  22. };
  23. class not_an_array_exception :
  24. public malformed_json_exception {
  25. public:
  26. template <typename T>
  27. not_an_array_exception(T const &)
  28. : not_an_array_exception(typeid(T).name()) {}
  29. private:
  30. not_an_array_exception(char const * tname);
  31. };
  32. struct malformed_object_key :
  33. public malformed_json_exception {
  34. malformed_object_key(char instead);
  35. };
  36. struct malformed_object_association :
  37. public malformed_json_exception {
  38. malformed_object_association(char instead);
  39. };
  40. class unterminated_json_exception :
  41. public malformed_json_exception {
  42. using malformed_json_exception::malformed_json_exception;
  43. };
  44. struct unterminated_json_array :
  45. public unterminated_json_exception {
  46. unterminated_json_array();
  47. };
  48. struct unterminated_json_object :
  49. public unterminated_json_exception {
  50. unterminated_json_object();
  51. };
  52. class json_numeric_exception :
  53. public std::domain_error {
  54. using std::domain_error::domain_error;
  55. };
  56. class json_numeric_width_exception :
  57. public json_numeric_exception {
  58. using json_numeric_exception::json_numeric_exception;
  59. };
  60. }