Skip to content

Add std::error_code and error category constructors to system_error#331

Open
Seele-Official wants to merge 1 commit into
jeremy-rifkin:devfrom
Seele-Official:feature/issue-326
Open

Add std::error_code and error category constructors to system_error#331
Seele-Official wants to merge 1 commit into
jeremy-rifkin:devfrom
Seele-Official:feature/issue-326

Conversation

@Seele-Official

Copy link
Copy Markdown

Summary

This PR extends cpptrace::system_error with constructors accepting:

  • std::error_code
  • An error value together with a const std::error_category&
  • Both forms with an optional custom message

This brings cpptrace::system_error closer to the interface provided by std::system_error.

Details

The existing (int, std::string&&) constructor has been preserved for source compatibility. Its implementation now delegates to the new std::error_code constructor using std::generic_category(), preserving the existing behavior while avoiding duplicate initialization and message-formatting logic.

I intentionally did not reproduce the complete set of message overloads provided by std::system_error, which accepts both const char* and const std::string&. The existing cpptrace exception hierarchy consistently accepts messages as std::string&&, so this PR follows that convention and keeps the change focused on error-code and error-category support.

In the longer term, I think it would be useful for cpptrace's exception types, not only system_error, to support const char* and const std::string& as well (refer to https://en.cppreference.com/cpp/header/stdexcept). Although string literals can currently be passed through an implicit conversion, doing so requires constructing a temporary std::string. Dedicated overloads would improve compatibility with the standard exception types, make the API more convenient to use, and may avoid unnecessary temporary construction or moves.

Closes #326

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.

1 participant