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.
Let's take a simple example:
On a first glance, this should print the time the stream_info was created at.
On a second glance, the format is called
float64
, notdouble64
so an exception should be thrown and the function should return.In reality, a
lsl::stream_info
object is created, but the internal pointer is set to 0 so the call toinfo.created_at()
will dereference a null pointer and everything will crash.This PR first adds the helper macro
LSL_CATCH_EXCEPTIONS
and the helper functioncreate_object_noexcept
for the C-API to convert exceptions to error codes and copy the error message to an internal variable. The last error message can then be retrieved via thelsl_last_error()
function.After that, the C++ wrapper can check for errors (i.e. is the returned pointer valid) or throw an exception with the last error message.