Exception handling in Boost.Asio

Posted by Alex B on Stack Overflow See other posts from Stack Overflow or by Alex B
Published on 2010-06-18T00:44:46Z Indexed on 2010/06/18 0:53 UTC
Read the original article Hit count: 280

Filed under:
|
|

Boost.Asio documentation suggests the following exception handling pattern:

boost::asio::io_service io_service;
...
for (;;)
{
  try
  {
    io_service.run();
    break; // run() exited normally
  }
  catch (my_exception& e)
  {
    // Deal with exception as appropriate.
  }
}

The problem with it is that the context of exception is lost at the point when it's handled. For example, if I have multiple socket sessions going on, I don't know which one caused the exception to be thrown.

What would be a better way to handle the exceptions from asynchronous handlers without wrapping them in try/catch blocks?

© Stack Overflow or respective owner

Related posts about c++

Related posts about boost