Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BOOST_AUTO_TEST_CASE( exception_in_thread )
- {
- fc::thread thread("my");
- std::atomic<int> counter;
- counter = 0;
- class my_exception : public std::exception
- {
- public:
- my_exception(int t) : thread_id(t) {}
- const char* what() const throw ()
- {
- return (std::string("Error in thread ") + std::to_string(thread_id)).c_str();
- }
- int thread_id;
- };
- try {
- auto future1 = thread.async( []() { ilog("In async1"); throw my_exception(1); });
- auto future2 = thread.async( []() { ilog("In async2"); throw my_exception(2); });
- auto future3 = thread.async( []() { ilog("In async3"); throw my_exception(3); });
- future1.wait();
- future2.wait();
- future3.wait();
- }
- catch (const my_exception& e)
- {
- counter++;
- elog("Exception caught on another fc::thread: ${msg}", ("msg", e.what() ));
- }
- // is thread still alive?
- auto future = thread.async([]() { return; });
- future.wait();
- ilog("Counter was called ${cnt} times.", ("cnt", counter) );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement