c++ - Catch exception in boost::property_tree::read_xml -


I am trying to capture the exception which is boost :: property_tree :: xml_parser :: read_xml . Here is my example program:

  #include & lt; Iostream & gt; # Include & lt; Boost / property_tree / ptree.hpp & gt; # Include & lt; Boost / property_tree / xml_parser.hpp & gt; Int main (int argc, char ** argv) {boost :: property_tree :: ptree pt; Std :: Court & lt; & Lt; "123,123" & lt; & Lt; Std :: endl; Try {std :: court & lt; & Lt; "Read" & lt; & Lt; Argv [1] is referred to as & lt; & Lt; Std :: endl; Read_xml (argv [1], PT); } Hold (const boost :: property_tree :: xml_parser :: xml_parser_error & ex) {std :: cout & lt; & Lt; Argv [1] & lt; & Lt; "Failed, Reading" & lt; & Lt; Argv [2] & lt; & Lt; Std :: endl; Read_xml (argv [2], PT); }}   

Output is:

  123123 read 123.xml [1] 9 7028 abort ./a.out 123.xml 345.xml   

What am I doing wrong? Obviously the exception is not caught. I too tried to capture (...) everything through and try to catch std :: exception along with boost :: exception . The result is the same in all cases. According to the promotion of the document should be thrown a xml_parser_error. My promotion version is 1.54.

Little update: When I do not try to execute read_xml ("notAvalidFilePAth", pt), then I want to promote

  After throwing an example, it is said: exception_detail :: clone_impl & lt; Boost :: exception_detail :: error_info_injector & lt; Boost :: property_tree :: xml_parser :: xml_parser_error & gt; & Gt; Can not open '(): 123.xml: file   

and when I run it with GDB I get:

  Read Finish 'promotion: exception_detail :: clone_impl & lt; :: exception_detail :: error_info_injector promote & lt; Promote: property_tree :: xml_parser :: xml_parser_error & gt; & Gt; '(): PATH = / usr / bin: / bin: / usr / sbin: / sbin: / usr / local / bin: / opt / x11 / bin: / usr / local / macpgg2 / bin: / opt / local / Bin: / usr / texbin: / users / weidenka / bin: can not open the file program signal received SIGABRT, has been aborted. 0x00007fff8a31b866 __pthread_kill () in # 0x00007fff8a31b866 __pthread_kill () # 1 0x00007fff86c9f35c in pthread_kill () # 2 0x00007fff86240b1a in abort () # 3 0x00000001005547d5 __gnu_cxx :: __ verbose_terminate_handler ()   

Thanks in advance !

Good luck, Peter

This is your problem:

  read_xml (argv [2], pt);   

The fallback read operation is not against throwing exceptions, so when an exception occurs at this point, your program ends without flushing iostreams buffers.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -