Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve interoperability with std::system_error #131

Closed
wants to merge 1 commit into from

Conversation

apolukhin
Copy link
Member

@apolukhin apolukhin commented Dec 16, 2024

While migrating Boost.DLL to std::error_code boostorg/dll#76 I've noticed that boost::system_error is not related to std::system_error. Because of that, users have to duplicate the catch blocks if there's a need to work with error code:

try {
  some_throwing_function();
} catch (const std::system_error& err) {
  process_error_code(err.code());
} catch (const boost::system::system_error& err) {
  process_error_code(err.code());
}

With this PR the seconds catch block could be eliminated. Is there an interest in such functionality? The output of e.what() changes, is that OK?

@pdimov
Copy link
Member

pdimov commented Dec 16, 2024

No, it's not OK, because it throws away information, namely the source location associated with the error code. E.g. https://godbolt.org/z/Tcxf8TdY9.

I assume you don't care about this because you never added source locations to your error codes, but others have. :-)

This will also change the behavior of code like the one you show - the first catch block will start catching our system_error and the second one will never be reached.

@apolukhin apolukhin closed this Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants