I am creating a few std::threads that will be detached. I would like to have these running for a long time and would like these to handle exceptions themselves.
I create a thread using std::thread(Function) and have called detach before releasing the mutex and where Function does following:
void BlockStart() noexcept {
std::lock_guard<std::mutex> sync(lock);
}
void Function()
{
BlockStart();
try
{
throw;
}
catch(...)
{
std::cerr << "Caught something...\n";
}
}
Everytime I run this code, the exception handler is not called. The default handler of std::terminate() is called which calls abort.
How do I get an std::thread started thread to handle exceptions?