Argo  1.0
A C++ library for handling JSON.
Public Types | Public Member Functions | Static Public Attributes | Protected Attributes | List of all members
argo::json_exception Class Reference

Base class for all exceptions thrown by the library. More...

#include <json_exception.hpp>

Inheritance diagram for argo::json_exception:
argo::json_array_index_range_exception argo::json_invalid_key_exception argo::json_io_exception argo::json_parser_exception argo::json_pointer_exception argo::json_utf8_exception

Public Types

enum  exception_type {
  invalid_json_type_e, invalid_key_e, not_an_array_e, not_an_object_e,
  not_number_int_or_boolean_e, not_string_e, not_number_e, array_index_range_e,
  not_number_or_string_e, cant_compare_raw_e, cant_cast_raw_e, types_not_comparable_e,
  pointer_not_matched_e, pointer_token_type_invalid_e, fgetc_failed_e, read_failed_e,
  unexpected_result_from_read_e, write_fd_failed_e, write_file_failed_e, too_many_put_back_e,
  file_open_failed_e, invalid_character_e, invalid_number_e, number_out_of_range_e,
  number_too_long_e, string_too_long_e, unexpected_eof_e, unexpected_token_e,
  message_too_long_e, maximum_nesting_depth_exceeded_e, invalid_string_escape_e, invalid_string_encoding_e,
  invalid_unicode_e, invalid_utf8_char_e, invalid_utf8_sequence_length_e, invalid_hex_char_e,
  invalid_hex_number_e, syntax_error_in_pointer_string_e
}
 

Public Member Functions

 json_exception (exception_type et) noexcept
 
 json_exception (exception_type et, const char *json_type_name) noexcept
 
 json_exception (exception_type et, const char *first_json_type_name, const char *second_json_type_name) noexcept
 
exception_type get_type () const noexcept
 
virtual const char * what () const noexcept
 

Static Public Attributes

static const int max_message_length = 200
 Maximum length of the message that may be returned by the what() method.
 

Protected Attributes

char m_message [max_message_length]
 
exception_type m_type
 

Detailed Description

Base class for all exceptions thrown by the library.

Base class for all exceptions thrown by the library. All exeption types are defined here but subclasses are defined to provide specialised error message and extra parameters (e.g. the byte index where a JSON parsing error occured). For code that doesn't need to know anything about the specific exception and just wants to log an error message before exiting or continuing, catch exceptions of this class and call what() to get some human readable English text.

Definition at line 46 of file json_exception.hpp.

Member Enumeration Documentation

The type of the exception. It's a bit clunky but this also includes all the types for derived classes. That keeps the amount of code to a minimum and provides a single place to look up exception types. This exception class is really not intended to be subclassed outside of the library so that's not so bad.

Enumerator
invalid_json_type_e 

Internal error - the m_type member variable has an invalid value.

invalid_key_e 

Attempt to access a non-existent slot in a json instance.

not_an_array_e 

Attempt to call a method that assumes the json instance is an array.

not_an_object_e 

Attempt to call a method that assumes the json instance is an object.

not_number_int_or_boolean_e 

Attempt to call a method that assumes the json instance is a boolean or castable to one.

not_string_e 

Attempt to call a method that assumes the json instance is a string.

not_number_e 

Attempt to call a method that assumes the json instance is an int or double.

array_index_range_e 

Attempt to to access an index in an array object that is out of range.

not_number_or_string_e 

Attempt to construct an instance with a raw value that isn't a number or a string.

cant_compare_raw_e 

Raw values cannot be directly compared.

cant_cast_raw_e 

Raw values cannot be cast.

types_not_comparable_e 

Tried to compare two different types (e.g. int vs string)

pointer_not_matched_e 

Pointer doesn't point to anything in the json instance.

pointer_token_type_invalid_e 

Invalid pointer token type.

fgetc_failed_e 

The stdio fgetc call failed in an unexpected way.

read_failed_e 

The POSIX read() system call failed.

unexpected_result_from_read_e 

The POSIX read() system call returned an unexpected value.

write_fd_failed_e 

The POSIX write() system call failed.

write_file_failed_e 

The stdio fwrite() system call failed.

too_many_put_back_e 

Attempt to put back more than one character onto a reader.

file_open_failed_e 

Attempt to open file failed.

invalid_character_e 

An invalid character was found during parsing (e.g. ! outside of a string).

invalid_number_e 

Something that looked like a number ended up not being (e.g. 1234AAAA).

number_out_of_range_e 

A number was too large or small to convert accrurately to an int or double.

number_too_long_e 

A number had too many characters in it.

string_too_long_e 

A string had too many characters in it.

unexpected_eof_e 

The file ended where more tokens were expected.

unexpected_token_e 

A valid, but unexpected, lexical token was found (e.g. { {).

message_too_long_e 

Maximum message length was exceeded.

maximum_nesting_depth_exceeded_e 

Maximum nesting depth exceeded.

invalid_string_escape_e 

An invalid JSON character escape was found in a string. e.g. "\P".

invalid_string_encoding_e 

A string encoding of some sort was invalid (e.g. "\uAA").

invalid_unicode_e 

An invalid unicode code point was found when parsing a JSON string.

invalid_utf8_char_e 

An invalid UTF-8 character was found decoding or encoding a string.

invalid_utf8_sequence_length_e 

Internal error, couldn't determine the length of a UTF-8 sequence.

invalid_hex_char_e 

Invalid hex character was found. (e.g. "\uAA8Z").

invalid_hex_number_e 

Internal error, invalid hex number was found (< 0 or > 15).

syntax_error_in_pointer_string_e 

Syntax error parsing a pointer definition.

Definition at line 60 of file json_exception.hpp.

Constructor & Destructor Documentation

json_exception::json_exception ( exception_type  et)
noexcept

Constructor.

Definition at line 34 of file json_exception.cpp.

json_exception::json_exception ( exception_type  et,
const char *  json_type_name 
)
noexcept

Constructor when the error is a type related problem.

Definition at line 62 of file json_exception.cpp.

json_exception::json_exception ( exception_type  et,
const char *  first_json_type_name,
const char *  second_json_type_name 
)
noexcept

Constructor when the error is a type related problem involving two objects.

Definition at line 87 of file json_exception.cpp.

Member Function Documentation

json_exception::exception_type json_exception::get_type ( ) const
noexcept

Get the type of the exception. More details can be obtained for some sub-class exception types by calling methods specific to them.

Definition at line 107 of file json_exception.cpp.

const char * json_exception::what ( ) const
virtualnoexcept

Get a human readable English error message that can be used for logging or debugging purposes.

Definition at line 102 of file json_exception.cpp.

Member Data Documentation

char argo::json_exception::m_message[max_message_length]
protected

Error message. Held this way so as to allow the what() method to be declared noexcept.

Definition at line 183 of file json_exception.hpp.

exception_type argo::json_exception::m_type
protected

Specific type of the exception. Note that derived classes use this one too and don't define their own types.

Definition at line 189 of file json_exception.hpp.


The documentation for this class was generated from the following files: