From 9233cdd0146c8ed131b4d25ec57bef19395dfa3a Mon Sep 17 00:00:00 2001
From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com>
Date: Fri, 31 Jul 2020 17:49:10 +0200
Subject: [PATCH] Added exception handling for the main app itself
---
nw/__init__.py | 38 ++++++++++++++++++++++++++++++++++----
1 file changed, 34 insertions(+), 4 deletions(-)
diff --git a/nw/__init__.py b/nw/__init__.py
index 7b546c14..c3d08fcd 100644
--- a/nw/__init__.py
+++ b/nw/__init__.py
@@ -252,10 +252,10 @@ def main(sysArgs=None):
errMsg.setMinimumWidth(500)
errMsg.setMinimumHeight(300)
errMsg.showMessage((
- "ERROR: %s cannot start due to the following issues:
"
+ "ERROR: novelWriter cannot start due to the following issues:
"
" - %s
Exiting."
) % (
- CONFIG.appName, "
- ".join(errorData)
+ "
- ".join(errorData)
))
errApp.exec_()
sys.exit(1)
@@ -268,13 +268,43 @@ def main(sysArgs=None):
if testMode:
nwGUI = GuiMain()
return nwGUI
+
else:
nwApp = QApplication([CONFIG.appName, ("-style=%s" % qtStyle)])
nwApp.setApplicationName(CONFIG.appName)
nwApp.setApplicationVersion(__version__)
nwApp.setWindowIcon(QIcon(CONFIG.appIcon))
nwApp.setOrganizationDomain(__domain__)
- nwGUI = GuiMain()
- sys.exit(nwApp.exec_())
+
+ try:
+ nwGUI = GuiMain()
+ sys.exit(nwApp.exec_())
+
+ except:
+ # novelWriter has crashed!
+ from traceback import print_tb, format_tb
+
+ eInfo = sys.exc_info()
+ logger.critical("%s: %s" % (eInfo[0].__name__, eInfo[1]))
+ print_tb(eInfo[2])
+
+ del nwApp
+
+ errApp = QApplication([])
+ errMsg = QErrorMessage()
+ errMsg.setWindowTitle("Critical Error")
+ errMsg.setMinimumWidth(500)
+ errMsg.setMinimumHeight(300)
+ errMsg.showMessage((
+ "
%s:
%s
Traceback:
%s
Shutting down ...
" + ) % (eInfo[0].__name__, eInfo[1], "