Catch exceptions in background threads

This commit is contained in:
Dan Paulat 2024-06-12 01:03:58 -05:00
parent 863cdd0384
commit e1d61fccfa
13 changed files with 866 additions and 665 deletions

View file

@ -157,12 +157,19 @@ PlacefileManager::PlacefileManager() : p(std::make_unique<Impl>(this))
boost::asio::post(p->threadPool_,
[this]()
{
p->InitializePlacefileSettings();
try
{
p->InitializePlacefileSettings();
// Read placefile settings on startup
main::Application::WaitForInitialization();
p->ReadPlacefileSettings();
Q_EMIT PlacefilesInitialized();
// Read placefile settings on startup
main::Application::WaitForInitialization();
p->ReadPlacefileSettings();
Q_EMIT PlacefilesInitialized();
}
catch (const std::exception& ex)
{
logger_->error(ex.what());
}
});
}
@ -678,7 +685,7 @@ void PlacefileManager::Impl::PlacefileRecord::ScheduleRefresh()
}
else
{
Update();
UpdateAsync();
}
});
}
@ -691,7 +698,18 @@ void PlacefileManager::Impl::PlacefileRecord::CancelRefresh()
void PlacefileManager::Impl::PlacefileRecord::UpdateAsync()
{
boost::asio::post(threadPool_, [this]() { Update(); });
boost::asio::post(threadPool_,
[this]()
{
try
{
Update();
}
catch (const std::exception& ex)
{
logger_->error(ex.what());
}
});
}
std::shared_ptr<PlacefileManager> PlacefileManager::Instance()