Argo  1.0
A C++ library for handling JSON.
json_exception.hpp
Go to the documentation of this file.
1 #ifndef _json_exception_hpp_
2 #define _json_exception_hpp_
3 
4 /*
5  * Copyright (c) 2017 Andrew Haisley
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in all
15  * copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  */
25 
27 
28 #include <stdexcept>
29 
30 #include "common.hpp"
31 
32 namespace NAMESPACE
33 {
46  class json_exception : public std::exception
47  {
48  public:
49 
51  static const int max_message_length = 200;
52 
60  typedef enum
61  {
90 
105 
124 
139 
141  syntax_error_in_pointer_string_e
142  }
144 
148  json_exception(exception_type et) noexcept;
149 
153  json_exception(exception_type et, const char *json_type_name) noexcept;
154 
160  exception_type et,
161  const char *first_json_type_name,
162  const char *second_json_type_name) noexcept;
163 
169  exception_type get_type() const noexcept;
170 
175  virtual const char *what() const noexcept;
176 
177  protected:
178 
183  char m_message[max_message_length];
184 
189  exception_type m_type;
190 
191  };
192 
198  std::ostream &operator<<(std::ostream& stream, const json_exception &e);
199 }
200 
201 #endif
The POSIX read() system call returned an unexpected value.
Base class for all exceptions thrown by the library.
The stdio fwrite() system call failed.
#define NAMESPACE
You can change the namespace of the whole library by changing this value.
Definition: common.hpp:29
Internal error - the m_type member variable has an invalid value.
Attempt to to access an index in an array object that is out of range.
STL namespace.
Internal error, couldn&#39;t determine the length of a UTF-8 sequence.
Maximum message length was exceeded.
A string had too many characters in it.
A number had too many characters in it.
A number was too large or small to convert accrurately to an int or double.
Attempt to call a method that assumes the json instance is an array.
Internal error, invalid hex number was found (< 0 or > 15).
An invalid UTF-8 character was found decoding or encoding a string.
Attempt to access a non-existent slot in a json instance.
Attempt to put back more than one character onto a reader.
Common defs needed everywhere and, as far as is possible, platform specific changes.
Invalid hex character was found. (e.g. "\uAA8Z").
An invalid JSON character escape was found in a string. e.g. "\P".
The file ended where more tokens were expected.
Attempt to call a method that assumes the json instance is an int or double.
Pointer doesn&#39;t point to anything in the json instance.
Raw values cannot be directly compared.
The POSIX read() system call failed.
Attempt to call a method that assumes the json instance is an object.
Attempt to construct an instance with a raw value that isn&#39;t a number or a string.
A string encoding of some sort was invalid (e.g. "\uAA").
Something that looked like a number ended up not being (e.g. 1234AAAA).
Tried to compare two different types (e.g. int vs string)
An invalid character was found during parsing (e.g. ! outside of a string).
An invalid unicode code point was found when parsing a JSON string.
Attempt to call a method that assumes the json instance is a string.
Raw values cannot be cast.
A valid, but unexpected, lexical token was found (e.g. { {).
Attempt to call a method that assumes the json instance is a boolean or castable to one...
The POSIX write() system call failed.
The stdio fgetc call failed in an unexpected way.