Hey all, I've been looking over the Boost System library with an eye to making use of the system error codes functionality. Specifically, I want to use it to turn error codes returned by unix system calls like socket, accept, listen etc. into thrown exceptions. However, from the documentation I can't understand how I'm supposed to do this. Anybody know, or have good clear example code to share? Thanks, -- Geoff Nothing is ever easy.
On Mon, 12 Aug 2013 09:51:46 +0200, Geoff Shannon
Hey all,
I've been looking over the Boost System library with an eye to making use of the system error codes functionality. Specifically, I want to use it to turn error codes returned by unix system calls like socket, accept, listen etc. into thrown exceptions.
However, from the documentation I can't understand how I'm supposed to do this. Anybody know, or have good clear example code to share?
You can reuse error code values from boost/system/error_code.hpp or define your own error code values (have a look for example at boost/asio/error.hpp). Or is your question about something else? Boris
On Mon, Aug 12, 2013 at 10:03 AM, Boris Schaeling
You can reuse error code values from boost/system/error_code.hpp or define your own error code values (have a look for example at boost/asio/error.hpp). Or is your question about something else?
I was under the impression that there already were standard error codes corresponding to the standard errno values (which is what I'm interested in). So is there a well-defined way for specifically throwing errno based error_codes? I can't seem to do what is most obvious to me which is construct an exception with the value of errno. -- Geoff Nothing is ever easy.
Hi Geoff,
If I’m not mistaken, std:ystem_error was derived from Boost.
This being the case, you create an exception like this:
#include
On Tuesday, August 13, 2013, Leo Carreon wrote:
Hi Geoff,
If I’m not mistaken, std:[image: Confused smile]ystem_error was derived from Boost.
This being the case, you create an exception like this:
#include
. . . throw system_error(errno, system_category(), “whatever message”); AFAIK, you can also use generic_category() is you are dealing with POSIX error codes.
I hope this helps.
Regards, Leo
Thanks Leo, I actually just finally stumbled on the source comment that mentions the critical system_category that I was missing. -- Geoff
participants (3)
-
Boris Schaeling
-
Geoff Shannon
-
Leo Carreon