NDDEM
Classes | Macros | Typedefs | Enumerations | Functions
RapidJSON error handling

Classes

struct  ParseResult
 Result of parsing (wraps ParseErrorCode) More...
 

Macros

#define CEREAL_RAPIDJSON_ERROR_CHARTYPE   char
 Character type of error messages. More...
 
#define CEREAL_RAPIDJSON_ERROR_STRING(x)   x
 Macro for converting string literial to CEREAL_RAPIDJSON_ERROR_CHARTYPE[]. More...
 
#define CEREAL_RAPIDJSON_PARSE_ERROR_NORETURN(parseErrorCode, offset)
 Macro to indicate a parse error. More...
 
#define CEREAL_RAPIDJSON_PARSE_ERROR(parseErrorCode, offset)
 (Internal) macro to indicate and handle a parse error. More...
 

Typedefs

typedef const CEREAL_RAPIDJSON_ERROR_CHARTYPE *(* GetParseErrorFunc) (ParseErrorCode)
 Function pointer type of GetParseError(). More...
 

Enumerations

enum  ParseErrorCode {
  kParseErrorNone = 0 , kParseErrorDocumentEmpty , kParseErrorDocumentRootNotSingular , kParseErrorValueInvalid ,
  kParseErrorObjectMissName , kParseErrorObjectMissColon , kParseErrorObjectMissCommaOrCurlyBracket , kParseErrorArrayMissCommaOrSquareBracket ,
  kParseErrorStringUnicodeEscapeInvalidHex , kParseErrorStringUnicodeSurrogateInvalid , kParseErrorStringEscapeInvalid , kParseErrorStringMissQuotationMark ,
  kParseErrorStringInvalidEncoding , kParseErrorNumberTooBig , kParseErrorNumberMissFraction , kParseErrorNumberMissExponent ,
  kParseErrorTermination , kParseErrorUnspecificSyntaxError
}
 Error code of parsing. More...
 
enum  PointerParseErrorCode {
  kPointerParseErrorNone = 0 , kPointerParseErrorTokenMustBeginWithSolidus , kPointerParseErrorInvalidEscape , kPointerParseErrorInvalidPercentEncoding ,
  kPointerParseErrorCharacterMustPercentEncode
}
 Error code of parsing. More...
 

Functions

CEREAL_RAPIDJSON_NAMESPACE_BEGIN const CEREAL_RAPIDJSON_ERROR_CHARTYPEGetParseError_En (ParseErrorCode parseErrorCode)
 Maps error code of parsing into error message. More...
 

Detailed Description

Macro Definition Documentation

◆ CEREAL_RAPIDJSON_ERROR_CHARTYPE

#define CEREAL_RAPIDJSON_ERROR_CHARTYPE   char

Character type of error messages.

The default character type is char. On Windows, user can define this macro as TCHAR for supporting both unicode/non-unicode settings.

◆ CEREAL_RAPIDJSON_ERROR_STRING

#define CEREAL_RAPIDJSON_ERROR_STRING (   x)    x

Macro for converting string literial to CEREAL_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.

◆ CEREAL_RAPIDJSON_PARSE_ERROR

#define CEREAL_RAPIDJSON_PARSE_ERROR (   parseErrorCode,
  offset 
)

(Internal) macro to indicate and handle a parse error.

Parameters
parseErrorCoderapidjson::ParseErrorCode of the error
offsetposition of the error in JSON input (size_t)

Invokes CEREAL_RAPIDJSON_PARSE_ERROR_NORETURN and stops the parsing.

See also
CEREAL_RAPIDJSON_PARSE_ERROR_NORETURN

◆ CEREAL_RAPIDJSON_PARSE_ERROR_NORETURN

#define CEREAL_RAPIDJSON_PARSE_ERROR_NORETURN (   parseErrorCode,
  offset 
)
Value:
CEREAL_RAPIDJSON_ASSERT(!HasParseError()); /* Error can only be assigned once */ \
SetParseError(parseErrorCode, offset); \
CEREAL_RAPIDJSON_MULTILINEMACRO_END
#define CEREAL_RAPIDJSON_ASSERT(x)
Definition: json.hpp:50

Macro to indicate a parse error.

Parameters
parseErrorCoderapidjson::ParseErrorCode of the error
offsetposition of the error in JSON input (size_t)

This macros can be used as a customization point for the internal error handling mechanism of RapidJSON.

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 CEREAL_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) {}
};
ParseErrorCode
Error code of parsing.
Definition: error.h:64
Definition: json.hpp:5678
Result of parsing (wraps ParseErrorCode)
Definition: error.h:106
See also
CEREAL_RAPIDJSON_PARSE_ERROR, rapidjson::GenericReader::Parse

Typedef Documentation

◆ GetParseErrorFunc

typedef const CEREAL_RAPIDJSON_ERROR_CHARTYPE*(* GetParseErrorFunc) (ParseErrorCode)

Function pointer type of GetParseError().

This is the prototype for GetParseError_X(), where X is a locale. User can dynamically change locale in runtime, e.g.:

GetParseErrorFunc GetParseError = GetParseError_En; // or whatever
const CEREAL_RAPIDJSON_ERROR_CHARTYPE* s = GetParseError(document.GetParseErrorCode());
#define CEREAL_RAPIDJSON_ERROR_CHARTYPE
Character type of error messages.
Definition: error.h:39
CEREAL_RAPIDJSON_NAMESPACE_BEGIN const CEREAL_RAPIDJSON_ERROR_CHARTYPE * GetParseError_En(ParseErrorCode parseErrorCode)
Maps error code of parsing into error message.
Definition: en.h:36
const CEREAL_RAPIDJSON_ERROR_CHARTYPE *(* GetParseErrorFunc)(ParseErrorCode)
Function pointer type of GetParseError().
Definition: error.h:153

Enumeration Type Documentation

◆ ParseErrorCode

Error code of parsing.

See also
GenericReader::Parse, GenericReader::GetParseErrorCode
Enumerator
kParseErrorNone 

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.

◆ PointerParseErrorCode

Error code of parsing.

See also
GenericPointer::GenericPointer, GenericPointer::GetParseErrorCode
Enumerator
kPointerParseErrorNone 

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.

Function Documentation

◆ GetParseError_En()

Maps error code of parsing into error message.

Parameters
parseErrorCodeError code obtained in parsing.
Returns
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.