Classes | Macros | Typedefs | Enumerations | Functions
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(parseErrorCode, offset)
 (Internal) macro to indicate and handle a parse error. More...
 
#define RAPIDJSON_PARSE_ERROR_NORETURN(parseErrorCode, offset)
 Macro to indicate 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...
 
enum  PointerParseErrorCode {
  kPointerParseErrorNone = 0, kPointerParseErrorTokenMustBeginWithSolidus, kPointerParseErrorInvalidEscape, kPointerParseErrorInvalidPercentEncoding,
  kPointerParseErrorCharacterMustPercentEncode
}
 Error code of parsing. More...
 

Functions

RAPIDJSON_NAMESPACE_BEGIN const RAPIDJSON_ERROR_CHARTYPEGetParseError_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.

Definition at line 39 of file error.h.

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

Definition at line 52 of file error.h.

#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

Definition at line 120 of file reader.h.

#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:416

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

Definition at line 101 of file reader.h.

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());

Definition at line 197 of file error.h.

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.

Definition at line 64 of file error.h.

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.

Definition at line 37 of file pointer.h.

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.

Definition at line 36 of file en.h.



xbot_talker
Author(s): wangxiaoyun
autogenerated on Sat Oct 10 2020 03:27:54