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

  • Home
  • SEARCH
  • 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 6849241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:57:59+00:00 2026-05-27T00:57:59+00:00

I have a non-blocking function (it returns immediately) that creates a new thread to

  • 0

I have a non-blocking function (it returns immediately) that creates a new thread to parse some data:

boost::any Parse() throw(ParseException) {
  // parse something
}
typedef void (*HandlerFunc)(boost::any result);
void ParseAsync(HandlerFunc handler) {
  Parser me(*this);
  in_new_thread {
    boost::any result = me.Parse();
    handler(result);
  }
}

The problem is that Parse can throw an exception. What is the usual C++ way of handling these exceptions? Should I in some way “hand over” the exception to the handler function?

  • 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-05-27T00:58:00+00:00Added an answer on May 27, 2026 at 12:58 am

    The new C++11 standard support a number of facilities to ease thread programming.

    The most interesting, in your case, are std::future and std::promise.

    Note the std::promise::set_exception_* function. It allows you to channel an exception outside of its thread of origin (note std::exception_ptr has a shared pointer semantics). You can use std::current_exception() (in a catch statement) to get the required pointer.

    Then note the std::future::get function: if the promise the future is extracted from had an exception instead of a value, then it will throw the exception.

    This is the mechanism in place to channel exceptions from one thread to another.

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

Sidebar

Related Questions

I have a blocking function that executes an asynchronous MySQL query and returns the
I've been trying to deal with some delimited text files that have non standard
I have some non well-formed xml (HTML) data in JAVA, I used JAXP Dom,
I am playing a little with some non-blocking JavaScript loading. This means I have
I have a unit test that checks behavior on blocking and non-blocking sockets -
I have a non-.Net executable file that is included in my .net assembly as
We have a (non-web app) Spring application that throws a NoSuchBeanDefinitionException when running tests
I have an (non-virtualized) ItemsControl that binds its ItemsSource to a ObeservableCollection of ViewModel
say i have the 3 non blocking sends like this MPI_Isend (); MPI_Isend ();
Since i discovered the concept of non-blocking scripts i have become obsessed with loading

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.