json_exception.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 : public std::domain_error {
  13. using std::domain_error::domain_error;
  14. };
  15. struct not_an_object_exception : public malformed_json_exception {
  16. template <typename T>
  17. not_an_object_exception(T const &)
  18. : not_an_object_exception(typeid(T).name()) {}
  19. not_an_object_exception(char const * tname);
  20. };
  21. class not_an_array_exception : public malformed_json_exception {
  22. public:
  23. template <typename T>
  24. not_an_array_exception(T const &)
  25. : not_an_array_exception(typeid(T).name()) {}
  26. private:
  27. not_an_array_exception(char const * tname);
  28. };
  29. struct malformed_object_key : public malformed_json_exception {
  30. malformed_object_key(char instead);
  31. };
  32. struct malformed_object_association : public malformed_json_exception {
  33. malformed_object_association(char instead);
  34. };
  35. class unterminated_json_exception : public malformed_json_exception {
  36. using malformed_json_exception::malformed_json_exception;
  37. };
  38. struct unterminated_json_array : public unterminated_json_exception {
  39. unterminated_json_array();
  40. };
  41. struct unterminated_json_object : public unterminated_json_exception {
  42. unterminated_json_object();
  43. };
  44. class json_numeric_exception : public std::domain_error {
  45. using std::domain_error::domain_error;
  46. };
  47. class json_numeric_width_exception : public json_numeric_exception {
  48. using json_numeric_exception::json_numeric_exception;
  49. };
  50. }