From: Christopher Kohlhoff (chris_at_[hidden])
Date: 2006-11-14 06:39:17
Johan Nilsson <r.johan.nilsson_at_[hidden]> wrote:
> Imagine that you're implementing a "middle-layer" library,
> calling down to "lower-layer" methods that do the actual O/S
> specific calls. The lower-layer methods might be C methods, or
> a third-party library.
> Examples for comparison:
In my experience the lower layer tends to look more like:
foo(ec); // Called foo_impl() in your examples
if (ec) throw system_error(ec);
error_code foo(error_code& ec)
... windows implementation ...
ec = error_code(::GetLastError(), native_ecat);
... posix implementation ...
ec = error_code(errno, native_ecat);
At least, this is my understanding of how error_code and
system_error should be used. IMHO if the lowest level wrappers
use the error_code class in this way, there's no need for a
publicly available wrapper for ::GetLastError()/errno.
Having said that, I do have some "portable" helper functions
inside of asio to do effectively what you're proposing, However
they're only truly useful on a subset of the functions and are
mostly a hangover from before I switched asio to use
error_code/system_error. See clear_error() and error_wrapper()
in this file:
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk