Skip to content

Can system_error be modified to add the numerical error code in the message? #5782

@SoftdriveFelix

Description

@SoftdriveFelix

We have logs that contain error messages in various languages like japanese, spanish, french, arabic, etc which causes our bug investigations to be difficult. Having a numerical error code would at least allow us to look up the message online.

Looking at the source, I think the following can be changed in the system_error file in the _System_error class:

Current:

STL/stl/inc/system_error

Lines 466 to 473 in 85e4b57

static string _Makestr(error_code _Errcode, string _Message) { // compose error message
if (!_Message.empty()) {
_Message.append(": ");
}
_Message.append(_Errcode.message());
return _Message;
}

Suggested:

    static string _Makestr(error_code _Errcode, string _Message) { // compose error message
        if (!_Message.empty()) {
            _Message.append(": ");
        }
        _Message.append(to_string(_Errcode.value()));
        _Message.append(" - ");
        _Message.append(_Errcode.message());
        return _Message;
    }

When calling std::exception::what(), the error code would now be included.

This is just a proposition and I don't really mind the format itself. What's important is just the idea of adding the numerical code.

I wish it was possible to force FormatMessage to output english messages, but it doesn't work if the english package is not installed ☹️

Thanks,
Félix

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementSomething can be improved

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions