1
1

jsonException.hh 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. protected:
  26. const unsigned long long offset;
  27. const LinearHistory history;
  28. std::string _what;
  29. };
  30. /**
  31. * Expected JSon value (primitive / object / array), got crap
  32. **/
  33. class JsonNotJsonException: public JsonException
  34. {
  35. public:
  36. JsonNotJsonException(unsigned long long offet, LinearHistory &h);
  37. };
  38. /**
  39. * Expected char, got crap
  40. **/
  41. class JsonUnexpectedException: public JsonException
  42. {
  43. public:
  44. JsonUnexpectedException(const char expected, unsigned long long offset, LinearHistory &h);
  45. };
  46. /**
  47. * cannot interpret input as boolean/number
  48. **/
  49. class JsonFormatException: public JsonException
  50. {
  51. public:
  52. JsonFormatException(unsigned long long offset, LinearHistory &h);
  53. };
  54. /**
  55. * Invalid hexadecimal value
  56. **/
  57. class JsonHexvalueException: public JsonFormatException
  58. {
  59. public:
  60. JsonHexvalueException(const std::string &what, unsigned long long offset, LinearHistory &hist);
  61. JsonHexvalueException(const char what, unsigned long long offset, LinearHistory &hist);
  62. static std::string msg(char c);
  63. };
  64. /**
  65. * unknown escaped entry in string
  66. * (eg. \crap)
  67. **/
  68. class JsonEscapedException: public JsonException
  69. {
  70. public:
  71. JsonEscapedException(char c, unsigned long long offset, LinearHistory &h);
  72. protected:
  73. const char c;
  74. };