Dear expert, I’m looping over all the child of the root of an xml and I want to see what appens when the child is not found, for example I’m searching for UserInfo child:
there are two UserInfo child at the end of the xml, but no “xyz” child. I get:
Options
Variables
Spectators
Classes
Targets
Transformations
MVAPdfs
Weights
UserInfo
UserInfo
Error: Symbol #include is not defined in current scope (tmpfile):1:
Error: Symbol exception is not defined in current scope (tmpfile):1:
Syntax Error: #include <exception> (tmpfile):1:
Error: Symbol G__exception is not defined in current scope (tmpfile):1:
Error: type G__exception not defined FILE:(tmpfile) LINE:1
(void)0
*** Interpreter error recovered ***
all the names of the child are correct, but at the end something strange happens.
Well, before you use any “pointer”, make sure it’s not 0.
If “xml.GetNodeName(user_info_node)” returns 0, then “string(xml.GetNodeName(user_info_node))” will crash … for example: root [0] const char *c = 0
root [1] string(c)
Error: Symbol #include is not defined in current scope (tmpfile):1:
Error: Symbol exception is not defined in current scope (tmpfile):1:
Syntax Error: #include <exception> (tmpfile):1:
Error: Symbol G__exception is not defined in current scope (tmpfile):1:
Error: type G__exception not defined FILE:(tmpfile) LINE:1
(class string)0
*** Interpreter error recovered ***
You might try something like: while ( user_info_node && xml.GetNodeName(user_info_node) && (string(xml.GetNodeName(user_info_node)) != "xyz") )
[quote=“Pepe Le Pew”]Well, before you use any “pointer”, make sure it’s not 0.
If “xml.GetNodeName(user_info_node)” returns 0, then “string(xml.GetNodeName(user_info_node))” will crash … for example: root [0] const char *c = 0
root [1] string(c)
Error: Symbol #include is not defined in current scope (tmpfile):1:
Error: Symbol exception is not defined in current scope (tmpfile):1:
Syntax Error: #include <exception> (tmpfile):1:
Error: Symbol G__exception is not defined in current scope (tmpfile):1:
Error: type G__exception not defined FILE:(tmpfile) LINE:1
(class string)0
*** Interpreter error recovered ***
You might try something like: while (user_info_node && xml.GetNodeName(user_info_node) && string(xml.GetNodeName(user_info_node)) != "xyz")[/quote]
ok, you’re right, but how can I understand this from
Error: Symbol #include is not defined in current scope (tmpfile):1:
First, say “hocus-pocus, abracadabra, .except” (laudly and clearly), then re-run your macro … root [0] .except
G__catchexception=0
root [1] const char *c = 0
root [2] string(c)
terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_S_construct NULL not valid
[quote=“Pepe Le Pew”]First, say “hocus-pocus, abracadabra, .except” (laudly and clearly), then re-run your macro … root [0] .except
G__catchexception=0
root [1] const char *c = 0
root [2] string(c)
terminate called after throwing an instance of 'std::logic_error'
what(): basic_string::_S_construct NULL not valid[/quote]
perfect, two items now:
why .except is not the default?
the throwing of an exception quit the ROOT session, can you do better? (I’m thinking something similar to the python interactive shell)
[quote]1. why .except is not the default?[/quote]Because we do not want the interactive shell to exit upon seeing an exception (see you point 2. ).
[quote]2. the throwing of an exception quit the ROOT session, can you do better? (I’m thinking something similar to the python interactive shell)[/quote]Try #include with which you might get better result. Either way we are planning on improving the situation but only in the context of Cling (i.e. in ROOT 6).