Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-06-27 07:39:48

Oliver.Kowalke_at_[hidden] wrote:
> Hello,
> creating a system_error requires :
> sys::error_code e( errno, sys::from_errno);
> std::string msg;
> sys::system_message( e, msg);
> sys::system_error( msg, e);
> I would find it easier if I had only to type:
> sys::error_code e( errno, sys::from_errno);
> sys::system_error( e); // what() == system_message

I agree.

system_error::system_error should have its arguments reversed and what_arg
should be optional. The postcondition of what() indicates that this might
have been the intent all along.

In addition, I think that the setters in error_code need to be dropped. In
the rare situations where an error_code is already available and needs to be
repurposed (a questionable activity as its original contents would be lost),
instead of:

    e.sysno_value( sv );

one would use:

    e = error_code( sv );

The postconditions of the constructors need to be changed to:

    sysno_value() == err && errno_value() == to_errno( err );


    errno_value() == err && sysno_value() == to_sysno( err );

respectively. sysno_value() and errno_value() now would need no further
(normative) explanations.

The postcondition of error() is ill-formed as currently given and -- in case
error() is provided at all (questionable) -- needs to be just errno_value()
== 0.

The current intrerface gives priority to system error codes as evidenced by
the single argument constructor. I could argue that we need to reverse that
and give priority to errno, but another approach would be to just give the
two equal standing with a from_sysno enum.

This would help code reviewers as in:

    sys::error_code e( r, sys::from_sysno );

it is now explicit that r is supposed to hold a system error code.

It isn't clear why there is no error_code::message() const. Probably to not
introduce a dependency on std::string and to avoid a copy. In my opinion, if
you have to convert error codes to strings in an inner loop where the copy
might be of any significance, you have already lost. :-) So I'd prefer the
user-friendlier approach of

    std::string error_code::message() const;
    std::wstring error_code::wmessage() const;

as people generally prefer members.

The introduction of operator== is also of questionable utility as it also
forces us to prefer one of the two codes over the other. If I want to
compare the system error codes, let me do so explicitly:

    e1.sysno_value() == e2.sysno_value()

This also helps code reviewers. Having an operator== for which e1 == e2
doesn't necessarily imply that e1 and e2 are equivalent would need much

Boost list run by bdawes at, gregod at, cpdaniel at, john at