Closed GoogleCodeExporter closed 9 years ago
I'm not sure I understand - is the runtime crash you're talking about an
uncaught
exception?
If so, this is the intended behavior! If you let an exception leak out of the
main()
function without being caught, the program will terminate. In Visual Studio, it
should say something like "uncaught exception: YAML::RepresentationException"
in the
debug window, I think.
If you want to access a node in a map without worrying about exceptions, use
`Node::FindValue`, which returns a pointer to the node instead of a reference.
if(const YAML::Node *pName = doc.FindValue("name")) {
std::string name;
*pName >> name;
std::cout << "Key 'name' exists, with value '" << name << "'\n";
} else {
std::cout << "Key 'name' doesn't exist\n";
}
See http://code.google.com/p/yaml-cpp/wiki/HowToParseADocument for more info
(look at
the section "Optional Keys".
Original comment by jbe...@gmail.com
on 15 Sep 2009 at 2:22
Yes the message is about an unhandled exception and in the commandline appears:
"This
application has requested the Runtime to terminate it in an unusual way. Please
contact the application's support team for more information."
So this is a normal behaviour?
Original comment by patle...@gmail.com
on 15 Sep 2009 at 2:56
BTW I noticed that the Line and Column info in the exception message doesn't
match
well with the real place of the error.
Original comment by patle...@gmail.com
on 15 Sep 2009 at 2:57
Yes, this is normal behavior. You should to catch and handle exceptions, if you
can.
How else would you like yaml-cpp to tell you that the key doesn't exist?
Think about it this way: by calling
node["name"]
we must return a reference to a const Node (of the value corresponding to the
key
"name"). If the key doesn't exist, what should we return? There are no null
references, so the function operator[] can't fulfill its contract, so it throws
an
exception.
For the line/column info, it probably refers to the start of the map node that
you're
inspecting. Since the key wasn't found, we can't give the line/column info of
the key
that you *meant* to use (since we don't know!).
I'm going to mark this issue as "Invalid" since it's intended behavior.
Original comment by jbe...@gmail.com
on 15 Sep 2009 at 8:39
About the line/column info of the occurring error place: I tried to produce
several
different errors and it never matched the right place. At best it found the
right line.
Thanks for your help.
Original comment by patle...@gmail.com
on 15 Sep 2009 at 8:53
Do you have an example of the line/column problem?
Original comment by jbe...@gmail.com
on 15 Sep 2009 at 9:31
Original issue reported on code.google.com by
patle...@gmail.com
on 15 Sep 2009 at 12:55