22

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 ?

Sam Miller
  • 23,808
  • 4
  • 67
  • 87
user1307957
  • 541
  • 3
  • 8
  • 19
  • What type is error? What is function is populating the error field? – Jon Cage May 25 '12 at 13:16
  • possible duplicate of [How to decipher a boost asio ssl error code?](http://stackoverflow.com/questions/9828066/how-to-decipher-a-boost-asio-ssl-error-code) – Jon Cage May 25 '12 at 13:18
  • Try this as well: http://stackoverflow.com/questions/2448715/verbosity-in-boost-asio-using-ssl – Jon Cage May 25 '12 at 13:22
  • Note that if you intend to display such errors to your users, you probably should do it in a way it can be localized. – ereOn May 25 '12 at 13:28
  • @JonCage: I disagree about the "duplicate", those questions asked how to work around the issue or provide more logs, but not how to get human-friendly messages. – Matthieu M. May 25 '12 at 13:59
  • @Matthieu: That's not what 'Is there any better way how to display error' sounded like to me - I thought he wanted to know what the error meant. Happy to accept I misinterpreted the OPs question though.. – Jon Cage May 25 '12 at 14:22

1 Answers1

43

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.

betabandido
  • 18,946
  • 11
  • 62
  • 76