Support for building with exceptions disabled #1146
+87
−64
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There are currently three issues for supporting compilation without exceptions
resolves #196 (closed with no changes)
resolves #799 (open, no interaction)
resolves #930 (open, no interaction)
these issue mention the following use case:
using the library for a project where external constraints force it to build without exceptions (e.g. game development, embedded)
My use case is a C++ application that I compile with exceptions enabled for Linux/Windows but also with emscripten for WebAssembly where I disable exceptions.
YAML_CPP_NORETURN
to annotate functions as not returning indll.h
YAML_throw<ExceptionType>(args...)
inexception.h
this function will throw an exception unless exceptions are disabled in the compiler,
detected by checking the pre-defined macro
__cpp_exceptions
In this case the exception class will be instantiated, and the user-provided function
YAML::handle_exception(const char*)
will be called on the exception'swhat()
methodYAML::handle_exception
,there will be a linker error
sed -i "s/throw \([A-Za-z]*\)(\(.*\))/YAML_throw<\1>(\2)/g"
throw statements for non-templated exceptionssed -i "s/throw \(.*\)<\(.*\)>(/YAML_throw<\1<\2> >(/g"
throw statements for templated exceptions