From abe05dbdd77eea18cdee4f64ec04308019f55c13 Mon Sep 17 00:00:00 2001 From: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com> Date: Tue, 15 Dec 2015 17:53:56 -0500 Subject: [PATCH] manager: catch exceptions in mainloop This patch prevents exceptions to crash application if happen during pollEvents() processing. Exception are just catch and displayed. In case of exception caused by a task, this one is removed from pending list. Handlers are not removed, take care of that! Change-Id: I266539585baf68f329d53f3d20361c4cb08211f3 Tuleap: #200 --- src/manager.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/manager.cpp b/src/manager.cpp index 3dda290383..e6561652cf 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -1407,7 +1407,11 @@ void Manager::pollEvents() // Think twice before modify this code. nextEventHandler_ = std::next(iter); - iter->second(); + try { + iter->second(); + } catch (const std::exception& e) { + RING_ERR("MainLoop exception (handler): %s", e.what()); + } iter = nextEventHandler_; } } @@ -1422,7 +1426,14 @@ void Manager::pollEvents() return; auto next = std::next(iter); - if (not (*iter)()) + bool result; + try { + result = (*iter)(); + } catch (const std::exception& e) { + RING_ERR("MainLoop exception (task): %s", e.what()); + result = false; + } + if (not result) tmpList.erase(iter); iter = next; } -- GitLab