Skip to content
JasonPP::

Exceptions

Ah yes, exceptions. A true love/hate relationship.
Nonetheless it is useful to know what they mean!

Ah, if you're stuck with an exception

Remember to catch and print its what()!
There's almost always additional information about the thing that went wrong!


JsonException
The base class of all JasonPP exceptions.
If you just say "screw it, i want to catch 'em all", you could just catch a JsonException



JsonWrongDataTypeException
If you encounter a JsonWrongDataTypeException, you will have most likely tried to, well, get the wrong datatype of an object!
For example, you have this json:

{
    "age": 15
}

and you try to get the string-value of age. This would lead to a JsonWrongDataTypeException.

Remember, you can always check:
json.GetDataType()==JSON_DATA_TYPE::INT



JsonLabelDoesNotExistException
A JsonLabelDoesNotExistException is raised, if you try to Get() a label that does not exist!
For example, you have this json:

{
    "age": 15
}

and you try to get the value of field name.
Are you looking for json.Set()?



JsonLabelAlreadyExistsException
A JsonLabelAlreadyExistsException is raised, if you try to Add() an Element that does already exist! For example, you have this json:

{
    "age": 15
}

and you try to add a new field called age.
Are you looking for json.Set()?



JsonShorthandInvalidException
A JsonShorthandInvalidException is raised, if you try to use an invalid shorthand in a shorthand function.
A shorthands validity depends on the function that it is used for. See the references of



JsonNoParentAvailableException
A JsonNoParentAvailableException is raised, if you try to GetParent() of an object that has no parent.

Remember, you can always check:
if (myJsonData.HasParent())



JsonArrayOutOfRangeException
A JsonArrayOutOfRangeException is raised, if you try to access an index of a JsonArray that does not exist.
Eg arr[-1] or arr[arr.Size() + 1].
This also goes for any other function taking an index for a JsonArray.



Parsing exceptions

For when you try to parse invalid json



JsonParsingUnrecognizableDatatypeException
is raised, if the DataType is unrecognizeable. For example:

{
    "age": Papaya
}



JsonParsingDuplicateLabelException
is raised, if the json has duplicate labels. For example:

{
    "age": 5,
    "age": 12
}



JsonParsingExpectedEOFException
is raised, if the parser would have expected the end of it's string, but got something else.
Most likely an error in the json's syntax.



JsonParsingMissingQuotesException
is raised, if something is wrong with the jsons quotes.



JsonParsingMissingBracketsException
is raised, if something is wrong with the jsons brackets.



JsonParsingUTFSequenceException
is raised, if an invalid utf escape sequence is detected.
For example:

  • \u03ge Not valid hex
  • \u0 Not 4 places long
  • \u No hex values at all



JsonParsingGeneralException
For everything else, there's JsonParsingGeneralException.
Could be anything ¯\_(ツ)_/¯. Most likely faulty json tho.