jsonException.hh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /**
  2. * jsonException.hh for jsonstroller
  3. *
  4. * Author: isundil <isundill@gmail.com>
  5. **/
  6. #pragma once
  7. #include <exception>
  8. #include "config.h"
  9. #include "linearHistory.hh"
  10. /**
  11. * Reach end of input prematurelly
  12. **/
  13. class EofException: public std::exception
  14. { };
  15. /**
  16. * std json parse exception
  17. **/
  18. class JsonException: public std::exception
  19. {
  20. public:
  21. JsonException(const std::string &what, unsigned long long offset, LinearHistory &buf);
  22. std::string getHistory() const;
  23. const char *what() const noexcept;
  24. unsigned int currentLine() const;
  25. unsigned int currentCol() const;
  26. protected:
  27. const unsigned long long offset;
  28. const LinearHistory history;
  29. std::string _what;
  30. };
  31. /**
  32. * Expected JSon value (primitive / object / array), got crap
  33. **/
  34. class JsonNotJsonException: public JsonException
  35. {
  36. public:
  37. JsonNotJsonException(unsigned long long offet, LinearHistory &h);
  38. };
  39. /**
  40. * Expected char, got crap
  41. **/
  42. class JsonUnexpectedException: public JsonException
  43. {
  44. public:
  45. JsonUnexpectedException(const char expected, unsigned long long offset, LinearHistory &h);
  46. };
  47. /**
  48. * cannot interpret input as boolean/number
  49. **/
  50. class JsonFormatException: public JsonException
  51. {
  52. public:
  53. JsonFormatException(unsigned long long offset, LinearHistory &h);
  54. };
  55. /**
  56. * Invalid hexadecimal value
  57. **/
  58. class JsonHexvalueException: public JsonFormatException
  59. {
  60. public:
  61. JsonHexvalueException(const std::string &what, unsigned long long offset, LinearHistory &hist);
  62. JsonHexvalueException(const char what, unsigned long long offset, LinearHistory &hist);
  63. static std::string msg(char c);
  64. };
  65. /**
  66. * unknown escaped entry in string
  67. * (eg. \crap)
  68. **/
  69. class JsonEscapedException: public JsonException
  70. {
  71. public:
  72. JsonEscapedException(char c, unsigned long long offset, LinearHistory &h);
  73. protected:
  74. const char c;
  75. };