Boost error codes human-readable description

user1307957 picture user1307957 · May 25, 2012 · Viewed 17.5k times · Source

I'm catching errors in Boost Asio program like

if (!error)
{
    //do stuff
}
else
{
    std::cout << "Error : " << error << std::endl;
    //handle error
}

But the error isn't human-readable (e.g. connecting to SSL server without certificate gives error asio.ssl:335544539). Is there any better way how to display error ?

Answer

betabandido picture betabandido · May 25, 2012

If you are likely using boost::system::error_code you can call:

error.message()

to get a more human-friendly message.

Using operator<< translates into:

os << ec.category().name() << ':' << ec.value()

Here you can check a detailed overview of the available members in error_code.