Boost logo

Boost :

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: void foo() { error_code ec; foo(ec); // Called foo_impl() in your examples if (ec) throw system_error(ec); } error_code foo(error_code& ec) { #ifdef BOOST_WINDOWS ... windows implementation ... ec = error_code(::GetLastError(), native_ecat); #else ... posix implementation ... ec = error_code(errno, native_ecat); #endif return ec; } 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: http://boost.cvs.sourceforge.net/*checkout*/boost/boost/boost/asio/detail/socket_ops.hpp?revision=1.5 Cheers, Chris


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk