TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
RapidJSON error handling

Classes

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

Macros

#define RAPIDJSON_ERROR_CHARTYPE   char
 Character type of error messages. More...
 
#define RAPIDJSON_ERROR_STRING(x)   x
 Macro for converting string literial to RAPIDJSON_ERROR_CHARTYPE[]. More...
 
#define RAPIDJSON_PARSE_ERROR_NORETURN(parseErrorCode, offset)
 Macro to indicate a parse error. More...
 
#define RAPIDJSON_PARSE_ERROR(parseErrorCode, offset)
 (Internal) macro to indicate and handle a parse error. More...
 

Typedefs

typedef const
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...
 

Functions

RAPIDJSON_NAMESPACE_BEGIN
const RAPIDJSON_ERROR_CHARTYPE
GetParseError_En (ParseErrorCode parseErrorCode)
 Maps error code of parsing into error message. More...
 

Detailed Description

Macro Definition Documentation

#define 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.

#define 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.

#define 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 RAPIDJSON_PARSE_ERROR_NORETURN and stops the parsing.

See also
RAPIDJSON_PARSE_ERROR_NORETURN
#define RAPIDJSON_PARSE_ERROR_NORETURN (   parseErrorCode,
  offset 
)
Value:
RAPIDJSON_ASSERT(!HasParseError()); /* Error can only be assigned once */ \
SetParseError(parseErrorCode, offset); \
RAPIDJSON_MULTILINEMACRO_END
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:344

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:

1 #define RAPIDJSON_PARSE_ERROR_NORETURN(parseErrorCode,offset) \
2  throw ParseException(parseErrorCode, #parseErrorCode, offset)
3 
4 #include <stdexcept> // std::runtime_error
5 #include "rapidjson/error/error.h" // rapidjson::ParseResult
6 
7 struct ParseException : std::runtime_error, rapidjson::ParseResult {
8  ParseException(rapidjson::ParseErrorCode code, const char* msg, size_t offset)
9  : std::runtime_error(msg), ParseResult(code, offset) {}
10 };
11 
12 #include "rapidjson/reader.h"
See also
RAPIDJSON_PARSE_ERROR, rapidjson::GenericReader::Parse

Typedef Documentation

typedef const 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.:

1 GetParseErrorFunc GetParseError = GetParseError_En; // or whatever
2 const RAPIDJSON_ERROR_CHARTYPE* s = GetParseError(document.GetParseErrorCode());

Enumeration Type Documentation

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.

59  {
60  kParseErrorNone = 0,
61 
64 
66 
70 
72 
78 
82 
85 };
No error.
Definition: error.h:60
Invalid value.
Definition: error.h:65
Parsing was terminated.
Definition: error.h:83
Missing a comma or '}' after an object member.
Definition: error.h:69
The document is empty.
Definition: error.h:62
Missing a comma or ']' after an array element.
Definition: error.h:71
Missing a name for object member.
Definition: error.h:67
Number too big to be stored in double.
Definition: error.h:79
Miss exponent in number.
Definition: error.h:81
Invalid escape character in string.
Definition: error.h:75
Invalid encoding in string.
Definition: error.h:77
Miss fraction part in number.
Definition: error.h:80
Incorrect hex digit after \u escape in string.
Definition: error.h:73
Unspecific syntax error.
Definition: error.h:84
The surrogate pair in string is invalid.
Definition: error.h:74
Missing a colon after a name of object member.
Definition: error.h:68
Missing a closing quotation mark in string.
Definition: error.h:76
The document root must not follow by other values.
Definition: error.h:63

Function Documentation

RAPIDJSON_NAMESPACE_BEGIN const RAPIDJSON_ERROR_CHARTYPE* GetParseError_En ( ParseErrorCode  parseErrorCode)
inline

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.
30  {
31  switch (parseErrorCode) {
32  case kParseErrorNone: return RAPIDJSON_ERROR_STRING("No error.");
33 
34  case kParseErrorDocumentEmpty: return RAPIDJSON_ERROR_STRING("The document is empty.");
35  case kParseErrorDocumentRootNotSingular: return RAPIDJSON_ERROR_STRING("The document root must not follow by other values.");
36 
37  case kParseErrorValueInvalid: return RAPIDJSON_ERROR_STRING("Invalid value.");
38 
39  case kParseErrorObjectMissName: return RAPIDJSON_ERROR_STRING("Missing a name for object member.");
40  case kParseErrorObjectMissColon: return RAPIDJSON_ERROR_STRING("Missing a colon after a name of object member.");
41  case kParseErrorObjectMissCommaOrCurlyBracket: return RAPIDJSON_ERROR_STRING("Missing a comma or '}' after an object member.");
42 
43  case kParseErrorArrayMissCommaOrSquareBracket: return RAPIDJSON_ERROR_STRING("Missing a comma or ']' after an array element.");
44 
45  case kParseErrorStringUnicodeEscapeInvalidHex: return RAPIDJSON_ERROR_STRING("Incorrect hex digit after \\u escape in string.");
46  case kParseErrorStringUnicodeSurrogateInvalid: return RAPIDJSON_ERROR_STRING("The surrogate pair in string is invalid.");
47  case kParseErrorStringEscapeInvalid: return RAPIDJSON_ERROR_STRING("Invalid escape character in string.");
48  case kParseErrorStringMissQuotationMark: return RAPIDJSON_ERROR_STRING("Missing a closing quotation mark in string.");
49  case kParseErrorStringInvalidEncoding: return RAPIDJSON_ERROR_STRING("Invalid encoding in string.");
50 
51  case kParseErrorNumberTooBig: return RAPIDJSON_ERROR_STRING("Number too big to be stored in double.");
52  case kParseErrorNumberMissFraction: return RAPIDJSON_ERROR_STRING("Miss fraction part in number.");
53  case kParseErrorNumberMissExponent: return RAPIDJSON_ERROR_STRING("Miss exponent in number.");
54 
55  case kParseErrorTermination: return RAPIDJSON_ERROR_STRING("Terminate parsing due to Handler error.");
56  case kParseErrorUnspecificSyntaxError: return RAPIDJSON_ERROR_STRING("Unspecific syntax error.");
57 
58  default:
59  return RAPIDJSON_ERROR_STRING("Unknown error.");
60  }
61 }
No error.
Definition: error.h:60
Invalid value.
Definition: error.h:65
Parsing was terminated.
Definition: error.h:83
Missing a comma or '}' after an object member.
Definition: error.h:69
The document is empty.
Definition: error.h:62
Missing a comma or ']' after an array element.
Definition: error.h:71
Missing a name for object member.
Definition: error.h:67
Number too big to be stored in double.
Definition: error.h:79
#define RAPIDJSON_ERROR_STRING(x)
Macro for converting string literial to RAPIDJSON_ERROR_CHARTYPE[].
Definition: error.h:47
Miss exponent in number.
Definition: error.h:81
Invalid escape character in string.
Definition: error.h:75
Invalid encoding in string.
Definition: error.h:77
Miss fraction part in number.
Definition: error.h:80
Incorrect hex digit after \u escape in string.
Definition: error.h:73
Unspecific syntax error.
Definition: error.h:84
The surrogate pair in string is invalid.
Definition: error.h:74
Missing a colon after a name of object member.
Definition: error.h:68
Missing a closing quotation mark in string.
Definition: error.h:76
The document root must not follow by other values.
Definition: error.h:63