There isn't necessarily a single "unrecognized key". For example, your YAML file might look like:
someKey: [blah]
someOtherKey: [blah]
or it might even be empty, e.g., {}
. In the former case, which one do you want? In the latter case, there are no keys.
You're asking for how to "get the key in a map", but maps can have zero or more keys.
As a side note, you can simplify some of this using the actual result of FindValue
, assuming you don't actually need the name of the key that you grabbed. For example:
const YAML::Node *pNode = doc.FindValue("goodKey");
if(!pNode)
pNode = doc.FindValue("alsoGoodKey");
if(!pNode)
throw std::runtime_error("unrecognized key");
(*pNode)["otherThing"] >> otherThingVar;
// etc