How to catch throws not from your thread?

So, we have pseudo code like:

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

and we started this thread with boost. We want to pass its error to another thread. How to do it?

+4
source share
3 answers

C ++ 11 defines the function current_exception (in the standard, section 18.8 Exception Handling) so that you can do just that.

Here's an MSDN article on carrying exceptions between threads that use this feature.

Since you are using Boost, here is the Boost documentation for current_exception and Boost article on transferring exceptions between threads .

+4
source

This MSDN article may be helpful.

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

To implement exception transport, Visual C ++ provides exception_ptr and current_exception, rethrow_exception, and copy_exception.

+1
source

You can not; exceptions occur in only one thread. However, you can use the top-level function for all exceptions and use a different mechanism to report an exception for the rest of your application.

0
source

Source: https://habr.com/ru/post/1401917/


All Articles