yaml-cpp

How to use yaml-cpp without exceptions support?


Is it possible to use yaml-cpp without exception support?

Currently, I use yaml-cpp-0.8.0. When I try to compile a program that uses yaml-cpp I get the following error:

external/yaml-cpp~override/src/scanscalar.cpp:52:11: error: cannot use 'throw' with exceptions disabled
   52 |           throw ParserException(INPUT.mark(), ErrorMsg::DOC_IN_SCALAR);
      |           ^

Since, I have exceptions disabled for performance reasons I wonder if there is a flag/define something that allows me to use yaml-cpp without exception support.


Solution

  • No, exceptions are hardcoded into the yaml-cpp library so there is no option to turn them off.

    The source for the particular function you are asking about looks like this:

    std::string ScanScalar(Stream& INPUT, ScanScalarParams& params) {
    //...
            if (params.onDocIndicator == THROW) {
              throw ParserException(INPUT.mark(), ErrorMsg::DOC_IN_SCALAR);
            }
    //...
    }
    

    ... and there are no #ifdefs or anything else that could disable the use of exceptions.


    On a more fundamental level, one of the most central classes in the library, the Yaml::Node, doesn't even have noexcept move semantics, which I raised an issue about in Make move constructor and assignment operator noexcept #809 and tried to fix, but I wasn't able to get that commit in.

    The question Is it possiable to disable exception? #930 was also raised.