Standard Library · json
class JsonRenderException
The error render() and renderPretty() raise for a value JSON cannot represent: a number built with JsonValue::ofNum that is infinite or NaN.
since 0.1.0-alpha.1linuxwindowswasm
- bases
RuntimeException
Overview
It is a RuntimeException, like the errors JsonValue.at raises, so catch (RuntimeException e) catches it too. The message is JSON has no representation for followed by Infinity, -Infinity or NaN.
Examples
use io::console;
use json;
use json::JsonValue;
float zero = 0.0;
JsonValue v = JsonValue::ofArray([JsonValue::ofNum(1.5), JsonValue::ofNum(1.0 / zero)]);
try {
console.writeln(v.render());
} catch (json::JsonRenderException e) {
console.writeln("caught: " + e.message);
}
caught: JSON has no representation for Infinity
Constructors
new
new(string msg)Creates the error with a message.
Parameters
- msg
- The text describing what could not be rendered.
Examples
use io::console;
use json;
json::JsonRenderException e = json::JsonRenderException("JSON has no representation for NaN");
console.writeln(e.message);
JSON has no representation for NaN