BGC Tools
Public Types | Public Member Functions | Properties | Static Private Member Functions
LightJson.Serialization.JsonParseException Class Reference

The exception that is thrown when a JSON message cannot be parsed. More...

Inheritance diagram for LightJson.Serialization.JsonParseException:
Inheritance graph
[legend]
Collaboration diagram for LightJson.Serialization.JsonParseException:
Collaboration graph
[legend]

Public Types

enum  ErrorType : int { ErrorType.Unknown = 0, ErrorType.IncompleteMessage, ErrorType.DuplicateObjectKeys, ErrorType.InvalidOrUnexpectedCharacter }
 Types of errors that can occur when parsing a JSON message. More...
 

Public Member Functions

 JsonParseException ()
 Initializes a new instance of JsonParseException. More...
 
 JsonParseException (ErrorType type, TextPosition position)
 Initializes a new instance of JsonParseException with the given error type and position. More...
 
 JsonParseException (string message, ErrorType type, TextPosition position)
 Initializes a new instance of JsonParseException with the given message, error type, and position. More...
 

Properties

TextPosition Position [get, private set]
 The text position where the error occurred. More...
 
ErrorType Type [get, private set]
 The type of error that caused the exception to be thrown. More...
 

Static Private Member Functions

static string GetDefaultMessage (ErrorType type)
 

Detailed Description

The exception that is thrown when a JSON message cannot be parsed.

Definition at line 8 of file JsonParseException.cs.

Member Enumeration Documentation

◆ ErrorType

Types of errors that can occur when parsing a JSON message.

Enumerator
Unknown 

The cause of the error is unknown.

IncompleteMessage 

The text ended before the message could be parsed.

DuplicateObjectKeys 

A JsonObject contains more than one key with the same name.

InvalidOrUnexpectedCharacter 

The parser encountered and invalid or unexpected character.

Definition at line 62 of file JsonParseException.cs.

62  : int
63  {
65  Unknown = 0,
66 
68  IncompleteMessage,
69 
71  DuplicateObjectKeys,
72 
74  InvalidOrUnexpectedCharacter,
75  }

Constructor & Destructor Documentation

◆ JsonParseException() [1/3]

LightJson.Serialization.JsonParseException.JsonParseException ( )
inline

Initializes a new instance of JsonParseException.

Definition at line 19 of file JsonParseException.cs.

20  : base(GetDefaultMessage(ErrorType.Unknown)) { }
static string GetDefaultMessage(ErrorType type)

◆ JsonParseException() [2/3]

LightJson.Serialization.JsonParseException.JsonParseException ( ErrorType  type,
TextPosition  position 
)
inline

Initializes a new instance of JsonParseException with the given error type and position.

Parameters
typeThe error type that describes the cause of the error.
positionThe position in the text where the error occurred.

Definition at line 27 of file JsonParseException.cs.

28  : this(GetDefaultMessage(type), type, position) { }
static string GetDefaultMessage(ErrorType type)

◆ JsonParseException() [3/3]

LightJson.Serialization.JsonParseException.JsonParseException ( string  message,
ErrorType  type,
TextPosition  position 
)
inline

Initializes a new instance of JsonParseException with the given message, error type, and position.

Parameters
messageThe message that describes the error.
typeThe error type that describes the cause of the error.
positionThe position in the text where the error occurred.

Definition at line 36 of file JsonParseException.cs.

37  : base(message)
38  {
39  Type = type;
40  Position = position;
41  }
ErrorType Type
The type of error that caused the exception to be thrown.
TextPosition Position
The text position where the error occurred.

Member Function Documentation

◆ GetDefaultMessage()

static string LightJson.Serialization.JsonParseException.GetDefaultMessage ( ErrorType  type)
inlinestaticprivate

Definition at line 43 of file JsonParseException.cs.

44  {
45  switch (type)
46  {
47  case ErrorType.IncompleteMessage:
48  return "The string ended before a value could be parsed.";
49 
50  case ErrorType.InvalidOrUnexpectedCharacter:
51  return "The parser encountered an invalid or unexpected character.";
52 
53  case ErrorType.DuplicateObjectKeys:
54  return "The parser encountered a JsonObject with duplicate keys.";
55 
56  default:
57  return "An error occurred while parsing the JSON message.";
58  }
59  }

Property Documentation

◆ Position

TextPosition LightJson.Serialization.JsonParseException.Position
getprivate set

The text position where the error occurred.

Definition at line 11 of file JsonParseException.cs.

◆ Type

ErrorType LightJson.Serialization.JsonParseException.Type
getprivate set

The type of error that caused the exception to be thrown.

Definition at line 14 of file JsonParseException.cs.

Referenced by LightJson.Serialization.TextScanner.Assert().


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