majintao0131 / yaml-cpp

Automatically exported from code.google.com/p/yaml-cpp
MIT License
0 stars 0 forks source link

Runtime Crash under Visual Studio 2008 under WinXP #43

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
0. When I parsed a .yml with a collection "namer:" instead of "name:" I got
a runtime crash (no way to debug this) until I discovered the
"YAML::RepresentationException"!
1. Entered wrong collection "namer:" instead of "name:"
2. Put parsing code into try-catch block which catches
"YAML::ParserException" only
3. Application crashes with Runtime Error, no debug possible.

What is the expected output? What do you see instead?
Not a crash. I see disaster!

What version of the product are you using? On what operating system?
Version 0.2.2

Please provide any additional information below.
Catching the error with "YAML::RepresentationException" fixed it so far.

Original issue reported on code.google.com by patle...@gmail.com on 15 Sep 2009 at 12:55

GoogleCodeExporter commented 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

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
Do you have an example of the line/column problem?

Original comment by jbe...@gmail.com on 15 Sep 2009 at 9:31