myWallJSON
myWallJSON

Reputation: 9502

How to catch throws not from your thread?

So say we have pseudocode like:

super_local_thread()
{
try{
throw err;
}catch(err)
{
throw err2;
}

and we had launched that thread with boost. We want to chath its error with another thread. How to do such thing?

Upvotes: 4

Views: 309

Answers (3)

Praetorian
Praetorian

Reputation: 109119

C++11 specifies a current_exception function (in the standard, section 18.8 Exception Handling) to allow you to do exactly that.

Here's an MSDN article on transporting exceptions between threads that makes use of this function.

Since you're using Boost, here's the Boost documentation for current_exception and Boost article on transporting exceptions between threads .

Upvotes: 4

Dmitriy Kachko
Dmitriy Kachko

Reputation: 2914

This MSDN article may be useful

http://msdn.microsoft.com/en-us/library/dd293602.aspx

To implement transporting exceptions, Visual C++ provides the exception_ptr type and the current_exception, rethrow_exception, and copy_exception functions.

Upvotes: 1

Ernest Friedman-Hill
Ernest Friedman-Hill

Reputation: 81684

You can't; exceptions only happen on a single thread. You can have your top-level function catch all exceptions, though, and use some other mechanism to report the exception to the rest of your application.

Upvotes: 0

Related Questions