c++ - boost::property_tree without exceptions -
i need parse ini files. this, i'm trying use boost::property_tree
, in system exceptions not allowed.
how can disable exception support when using boost::property_tree
?
if there's no way this, recommendations library appreciated.
after answer @sehe, tried piece of code, without success:
#include <iostream> #include <string> #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/ini_parser.hpp> namespace boost { void throw_exception(std::exception const& e) { std::cerr << "fake exception: " << e.what() << "\n"; std::exit(255); } } class foo { public: bool bar(const std::string file_name) { boost::property_tree::ptree prop_tree; boost::property_tree::read_ini(file_name, prop_tree); return !prop_tree.empty(); } };
the compilation line code uses following parameters:
-c -dboost_user_config="<user.hpp>" -dboost_no_exceptions -dboost_exception_disable -i.\toolchain\boost -i.\include foo.cpp
and finally, user.hpp
file:
#define boost_has_nrvo #define boost_no_complete_value_initialization #define boost_no_cxx11_auto_declarations #define boost_no_cxx11_auto_multideclarations #define boost_no_cxx11_char16_t #define boost_no_cxx11_char32_t #define boost_no_cxx11_constexpr #define boost_no_cxx11_decltype #define boost_no_cxx11_decltype_n3276 #define boost_no_cxx11_defaulted_functions #define boost_no_cxx11_deleted_functions #define boost_no_cxx11_explicit_conversion_operators #define boost_no_cxx11_final #define boost_no_cxx11_function_template_default_args #define boost_no_cxx11_lambdas #define boost_no_cxx11_local_class_template_parameters #define boost_no_cxx11_noexcept #define boost_no_cxx11_nullptr #define boost_no_cxx11_range_based_for #define boost_no_cxx11_raw_literals #define boost_no_cxx11_ref_qualifiers #define boost_no_cxx11_rvalue_references #define boost_no_cxx11_scoped_enums #define boost_no_cxx11_static_assert #define boost_no_cxx11_template_aliases #define boost_no_cxx11_unicode_literals #define boost_no_cxx11_unified_initialization_syntax #define boost_no_cxx11_user_defined_literals #define boost_no_cxx11_variadic_macros #define boost_no_cxx11_variadic_templates #define boost_no_sfinae_expr #define boost_no_two_phase_name_lookup
some errors returned compiler:
"boost/optional/optional.hpp", line 1047: error: #312: no suitable user-defined conversion "boost::bad_optional_access" "const std::exception" exists throw_exception(bad_optional_access()); ^ "boost/property_tree/string_path.hpp", line 221: error: #312: no suitable user-defined conversion "boost::property_tree::ptree_bad_path" "const std::exception" exists boost_property_tree_throw(ptree_bad_path("path syntax error", *this)); ^ "boost/property_tree/detail/ptree_implementation.hpp", line 78: error: #742: namespace "boost" has no actual member "iterator_core_access" friend class boost::iterator_core_access; ^
ps: i'm not using widely-available standard compiler, it's compiling boost::smart_ptr
, using same process described above.
you can configure boost exception not use exceptions:
you need define boost_no_exceptions
, further implement own c-style exception handling function, e.g.
void throw_exception(std::exception const& e) { std::cerr << "fake exception: " << e.what() << "\n"; std::exit(255); }
#define boost_no_exceptions #include <iostream> #include <boost/property_tree/ini_parser.hpp> namespace boost { void throw_exception(std::exception const& e) { std::cerr << "fake exception: " << e.what() << "\n"; std::exit(255); } } using namespace boost::property_tree; int main() { ptree pt; read_ini(std::cin, pt); write_ini(std::cout, pt.get_child("section5")); }
compiled
g++ -std=c++11 -o3 -wall -pedantic main.cpp -fno-exceptions
this prints
./test <<< "[section1]" fake exception: no such node (section5)
Comments
Post a Comment