Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8786569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:40:06+00:00 2026-06-13T21:40:06+00:00

If an app has only one io_service object and is threaded (see code below),

  • 0

If an app has only one io_service object and is threaded (see code below), what happens if one of the async handlers throw an exception. How does it propagate and more importantly whats the best way to handle them.

std::list< boost::shared_ptr< the_client > > clients_list;
for(int i = 0; i < n_threads; i++)
{
    clients_list.insert(boost::make_shared< the_client >( io_service, server_host, server_port ));
}

for(unsigned int i = 0; i < n_threads; i++)
{
    threads.create_thread(boost::bind(&boost::asio::io_service::run, boost::ref(io_service)));
}

for(std::list< boost::shared_ptr< the_client > >::iterator itr = clients_list.begin(); itr != clients_list.end(); ++itr)
{
    (*itr)->connect_to_server_and_run_statemachine();
}

Here the_client::connect_to_server_and_run_statemachine() sets up the connection to server and initiates the async connection handling.

I am aware of a question on a similar topic, but that doesn’t consider the multi-threaded io_service scenario.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T21:40:09+00:00Added an answer on June 13, 2026 at 9:40 pm

    Nothing magical happens. If you catch the exception somewhere, then your catch block handles it. Otherwise, an uncaught exception terminates the process.

    How you should handle it depends on what you want to happen. If the exception should never happen, then let it terminate the process. If you want to eat or handle the exceptions, then write a function that wraps io_service::run in a try/catch block and have the threads run that instead.

    I don’t like putting the intelligence that far from the code. My preferred solution is to never have my asynchronous functions throw exceptions unless there’s a truly fatal error. If an asynchronous function knows how to handle an exception it might throw, then it should catch it.

    However, it is perfectly acceptable to wrap run if that makes sense in your application.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My app only has one page - the MainPage. When the user selects new
I work on a app which has only one way to get a working
My app has to support landscape/portrait mode only for tablets, phones will only support
I am developing an app on iPad which has only animations. I am using
I have a new iPhone app that has the following (and only the following)
I have a winforms app and the main (and only) form has several buttons.
The app I'm working on has a self contained database. The only time I
I created a SQLite database that currently has only one table. I connected it
Recently I've been wondering about the fact that that an iOS app only has
My app has not only Users but also Admins and SuperAdmins. Since all three

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.