Boost, exceptions, threads, and asynchrony, how do I handle them?

I have many different threads ( boost::thread_pool) before boost::asio::io_service. io_servicewill call a function that will call async_read, which will call another one async_readfrom which many functions can be called. All this is done in two classes: the threads appear from the class Server, and are async_readcalled from the class Client.

I am provided throwfrom those functions that are called async_read(from a class Client), who will get the catchexception? Server? if so, is there a way to ignore the error and resume regular execution ?.

+3
source share
1 answer

Have you read this part of the Boost.Asio manual?

: " , throw(), run_one(), poll() poll_one(). , - , . .

, , catch.

UPDATE

, , , throw . try , catch - . ( ) .

void some_function()
{
    // do some work

    if (error_occurred) 
        // don't know context, so pass the buck to calling function
        throw std::exception;
}

void some_calling_function()
{
    try {
        some_function(); // could throw
    } catch (std::exception& e) {
        // do some error handling depending in context
    }
    // code will resume here
}
+3

All Articles