In some cases you don't want to treat end-of-file error code as an application-level error. If a remote peer close the connection then end-of-file error will be generated. You can obtain the underlying OS-level error code (which has type int). If you don't want to allocate additional std::string instance then you can use message(char const* buffer, std::size_t size) overload. To get a human-readable error description from the boost::system::error_code you should call message() member funtion which will return std::string with the error description. Asynchronous operation has been successfully completed So, to check if the operation has been successfully completed you should write something like: socket.async_connect(endpoint, (boost::system::error_code error) They pass boost::system::error_code into a completion handler instead. If you don't want to mess with exceptions, you can use return value overload: boost::system::error_code error Īsynchronous I/O functions don't throw exceptions. You can retrive the error_code from the system_error by calling code() member function: catch(boost::system::system_error const& e)īoost::system::error_code error = e.code() Exception approach tryĬatch(boost::system::system_error const& e) To return an error by reference, an instance of boost::system::error_code is used. When Boost.Asio function throws an exception, it throws an instance of boost::system::system_error which is inherited from the std::runtime_error exception class. Every synchronous I/O function in Boost.Asio has two overloads in order to deal with errors: the first one throws an exception, and the second one returns an error by reference (return value approach).