boostorg / leaf

Lightweight Error Augmentation Framework
Boost Software License 1.0
313 stars 48 forks source link

Conditionally unpack an error_id from a thrown system_error #15

Closed vector-of-bool closed 3 years ago

vector-of-bool commented 3 years ago

Previously, if a std::system_error was caught and passed to unpack_error_id, then the ex.code() would be unconditionally converted to an error_id, even if the code did not correspond to an actual error_id value. This effectively prevents reliable use of std::system_error as an exception type.

This tweaks to only consider the system_error to be an error_id if the code() of that error matches is_error_id().

zajo commented 3 years ago

Thanks! I also added a unit test that confirms that you are correct about the problem. I have to think a bit more and probably expand the unit test before I merge this into other branches (note I made a branch with name identical to the one you made).