I'm not sure if this will be a specific thing with jsoncpp or a general paradigm on how to make the C ++ library behave better. Basically I get this trace:
imagegeneratormanager.tsk: src/lib_json/json_value.cpp:1176: const Json::Value& Json::Value::operator[](const char*) const: Assertion `type_ == nullValue || type_ == objectValue' failed.
This happens when the input is bad. When the input - which comes from another application of mine through memcached - turns out to be bad, I would like to handle this error. You know, gracefully. Perhaps something like "error: entry for element 15006 is bad", going to the log. Not all my JSON string processing task crashes.
Is it just a poorly written library, or can you customize it more finely?
Edit: here is the call code:
Json::Value root; Json::Reader reader; succeeded = reader.parse(jsonString, root); if(!succeeded) { throw std::runtime_error(std::string("Failed to parse JSON for key ") + emailInfoKey.str()); } std::string userEmail = root.get("userId", "").asString(); std::string bodyFilePath = root.get("bodyFilePath", "").asString(); std::string msgId = root.get("msgId", "").asString();
source share