#include #include #include #include #include using namespace std ; exception_ptr global_eptr = nullptr; mutex eptr_mutex; void worker_function() { try { throw runtime_error("Something went wrong in the worker!"); } catch (...) { lock_guard lock(eptr_mutex); global_eptr = current_exception(); // Capture the exception } } int main() { thread worker(worker_function); worker.join(); // Wait for the worker to finish // Check if an exception was captured if (global_eptr) { try { //Throws the previous exception in exception_ptr rethrow_exception(global_eptr); // Rethrow the captured exception } catch (const exception& e1) { cerr << "Caught exception in main thread: " << e1.what() << endl; } } return 0; }