From de294dabca5867f343ef45b733f2da7e90330ca4 Mon Sep 17 00:00:00 2001 From: Benjamin Nauck Date: Sun, 29 Sep 2024 15:28:35 +0200 Subject: [PATCH] Include a warning to devs for unhandled exceptions The same situation will cause a crash on at least macOS. --- src/Gui/GuiApplication.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Gui/GuiApplication.cpp b/src/Gui/GuiApplication.cpp index 0e8f5ac730..b050e3ab8f 100644 --- a/src/Gui/GuiApplication.cpp +++ b/src/Gui/GuiApplication.cpp @@ -75,6 +75,16 @@ bool GUIApplication::notify (QObject * receiver, QEvent * event) (int)event->type()); return false; } + + // https://github.com/FreeCAD/FreeCAD/issues/16905 + std::string exceptionWarning = +#if FC_DEBUG + "Exceptions must be caught before they go through Qt." + " Ignoring this will cause crashes on some systems.\n"; +#else + ""; +#endif + try { if (event->type() == Spaceball::ButtonEvent::ButtonEventType || event->type() == Spaceball::MotionEvent::MotionEventType) @@ -89,14 +99,15 @@ bool GUIApplication::notify (QObject * receiver, QEvent * event) } catch (const Base::Exception& e) { Base::Console().Error("Unhandled Base::Exception caught in GUIApplication::notify.\n" - "The error message is: %s\n", e.what()); + "The error message is: %s\n%s", e.what(), exceptionWarning); } catch (const std::exception& e) { Base::Console().Error("Unhandled std::exception caught in GUIApplication::notify.\n" - "The error message is: %s\n", e.what()); + "The error message is: %s\n%s", e.what(), exceptionWarning); } catch (...) { - Base::Console().Error("Unhandled unknown exception caught in GUIApplication::notify.\n"); + Base::Console().Error("Unhandled unknown exception caught in GUIApplication::notify.\n%s", + exceptionWarning); } // Print some more information to the log file (if active) to ease bug fixing