From d16c35a17d2b44515413ca481e903f094d9d609d Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 14 Sep 2020 17:21:50 +0200 Subject: [PATCH] Gui: [skip ci] Coverity: Uncaught exception --- src/Gui/View3DInventorViewer.cpp | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index b28a1495aa..5102af85d1 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -1085,17 +1085,30 @@ void View3DInventorViewer::resetEditingRoot(bool updateLinks) ViewProviderLink::updateLinks(editViewProvider); } catch (const Py::Exception& e) { - Py::Object o = Py::type(e); - if (o.isString()) { - Py::String s(o); - Base::Console().Warning("%s\n", s.as_std_string("utf-8").c_str()); + /* coverity[UNCAUGHT_EXCEPT] Uncaught exception */ + // Coverity created several reports when removeViewProvider() + // is used somewhere in a destructor which indirectly invokes + // resetEditingRoot(). + // Now theoretically Py::type can throw an exception which nowhere + // will be handled and thus terminates the application. So, add an + // extra try/catch block here. + try { + Py::Object o = Py::type(e); + if (o.isString()) { + Py::String s(o); + Base::Console().Warning("%s\n", s.as_std_string("utf-8").c_str()); + } + else { + Py::String s(o.repr()); + Base::Console().Warning("%s\n", s.as_std_string("utf-8").c_str()); + } + // Prints message to console window if we are in interactive mode + PyErr_Print(); } - else { - Py::String s(o.repr()); - Base::Console().Warning("%s\n", s.as_std_string("utf-8").c_str()); + catch (Py::Exception& e) { + e.clear(); + Base::Console().Error("Unexpected exception raised in View3DInventorViewer::resetEditingRoot\n"); } - // Prints message to console window if we are in interactive mode - PyErr_Print(); } }