Skip to content

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