RapidJSON error handling
Classes:
Result of parsing (wraps ParseErrorCode)
Enumerations
ParseErrorCode { kParseErrorNone = 0 kParseErrorDocumentEmpty kParseErrorDocumentRootNotSingular kParseErrorValueInvalid kParseErrorObjectMissName kParseErrorObjectMissColon kParseErrorObjectMissCommaOrCurlyBracket kParseErrorArrayMissCommaOrSquareBracket kParseErrorStringUnicodeEscapeInvalidHex kParseErrorStringUnicodeSurrogateInvalid kParseErrorStringEscapeInvalid kParseErrorStringMissQuotationMark kParseErrorStringInvalidEncoding kParseErrorNumberTooBig kParseErrorNumberMissFraction kParseErrorNumberMissExponent kParseErrorTermination kParseErrorUnspecificSyntaxError }
Error code of parsing.
PointerParseErrorCode { kPointerParseErrorNone = 0 kPointerParseErrorTokenMustBeginWithSolidus kPointerParseErrorInvalidEscape kPointerParseErrorInvalidPercentEncoding kPointerParseErrorCharacterMustPercentEncode }
Error code of parsing.
Typedefs
GetParseErrorFunc )(ParseErrorCode)
Function pointer type of GetParseError().
Functions
GetParseError_En(ParseErrorCode parseErrorCode)
Maps error code of parsing into error message.
Defines
RAPIDJSON_ERROR_CHARTYPE() char
Character type of error messages.
Macro for converting string literial to RAPIDJSON_ERROR_CHARTYPE[].
RAPIDJSON_PARSE_ERROR(parseErrorCode, offset)
(Internal) macro to indicate and handle a parse error.
RAPIDJSON_PARSE_ERROR_NORETURN(parseErrorCode, offset) RAPIDJSON_MULTILINEMACRO_BEGIN \ (!HasParseError()); /* Error can only be assigned once */ \ SetParseError(parseErrorCode, offset); \ RAPIDJSON_MULTILINEMACRO_END
Macro to indicate a parse error.
Detailed Description
Enumerations
ParseErrorCode
Enumerator
- kParseErrorNone = 0
No error.
- kParseErrorDocumentEmpty
The document is empty.
- kParseErrorDocumentRootNotSingular
The document root must not follow by other values.
- kParseErrorValueInvalid
Invalid value.
- kParseErrorObjectMissName
Missing a name for object member.
- kParseErrorObjectMissColon
Missing a colon after a name of object member.
- kParseErrorObjectMissCommaOrCurlyBracket
Missing a comma or '}' after an object member.
- kParseErrorArrayMissCommaOrSquareBracket
Missing a comma or ']' after an array element.
- kParseErrorStringUnicodeEscapeInvalidHex
Incorrect hex digit after \u escape in string.
- kParseErrorStringUnicodeSurrogateInvalid
The surrogate pair in string is invalid.
- kParseErrorStringEscapeInvalid
Invalid escape character in string.
- kParseErrorStringMissQuotationMark
Missing a closing quotation mark in string.
- kParseErrorStringInvalidEncoding
Invalid encoding in string.
- kParseErrorNumberTooBig
Number too big to be stored in double.
- kParseErrorNumberMissFraction
Miss fraction part in number.
- kParseErrorNumberMissExponent
Miss exponent in number.
- kParseErrorTermination
Parsing was terminated.
- kParseErrorUnspecificSyntaxError
Unspecific syntax error.
Error code of parsing.
PointerParseErrorCode
Enumerator
- kPointerParseErrorNone = 0
The parse is successful.
- kPointerParseErrorTokenMustBeginWithSolidus
A token must begin with a '/'.
- kPointerParseErrorInvalidEscape
Invalid escape.
- kPointerParseErrorInvalidPercentEncoding
Invalid percent encoding in URI fragment.
- kPointerParseErrorCharacterMustPercentEncode
A character must percent encoded in URI fragment.
Error code of parsing.
GenericPointer::GenericPointer, GenericPointer::GetParseErrorCode
Typedefs
typedef const RAPIDJSON_ERROR_CHARTYPE *(* GetParseErrorFunc )(ParseErrorCode)
Function pointer type of GetParseError().
This is the prototype for
GetParseError_X(), where
Xis a locale. User can dynamically change locale in runtime, e.g.:
GetParseErrorFunc GetParseError = GetParseError_En; // or whatever const RAPIDJSON_ERROR_CHARTYPE* s = GetParseError(document.GetParseErrorCode());
Functions
GetParseError_En(ParseErrorCode parseErrorCode)
Maps error code of parsing into error message.
Parameters:
parseErrorCode | Error code obtained in parsing. |
the error message.
note:User can make a copy of this function for localization. Using switch-case is safer for future modification of error codes.
Defines
RAPIDJSON_ERROR_CHARTYPE() char
Character type of error messages.
The default character type is
char. On Windows, user can define this macro as
TCHARfor supporting both unicode/non-unicode settings.
RAPIDJSON_ERROR_STRING(x) x
Macro for converting string literial to RAPIDJSON_ERROR_CHARTYPE[].
By default this conversion macro does nothing. On Windows, user can define this macro as
_T(x)for supporting both unicode/non-unicode settings.
RAPIDJSON_PARSE_ERROR(parseErrorCode, offset)
(Internal) macro to indicate and handle a parse error.
Parameters:
parseErrorCode | rapidjson::ParseErrorCode of the error |
offset | position of the error in JSON input ( size_t) |
RAPIDJSON_PARSE_ERROR_NORETURN(parseErrorCode, offset) RAPIDJSON_MULTILINEMACRO_BEGIN \ (!HasParseError()); /* Error can only be assigned once */ \ SetParseError(parseErrorCode, offset); \ RAPIDJSON_MULTILINEMACRO_END
Macro to indicate a parse error.
Parameters:
parseErrorCode | rapidjson::ParseErrorCode of the error |
offset | position of the error in JSON input ( size_t) |
A common usage model is to throw an exception instead of requiring the caller to explicitly check the rapidjson::GenericReader::Parse's return value:
#define RAPIDJSON_PARSE_ERROR_NORETURN(parseErrorCode,offset) \ throw ParseException(parseErrorCode, #parseErrorCode, offset) #include <stdexcept> // std::runtime_error #include "rapidjson/error/error.h" // rapidjson::ParseResult struct ParseException : std::runtime_error, rapidjson::ParseResult { ParseException(rapidjson::ParseErrorCode code, const char* msg, size_t offset) : std::runtime_error(msg), ParseResult(code, offset) {} }; #include "rapidjson/reader.h"
RAPIDJSON_PARSE_ERROR, rapidjson::GenericReader::Parse