diff --git a/electrum/gui/qml/__init__.py b/electrum/gui/qml/__init__.py index 818ed39c6..f0113352b 100644 --- a/electrum/gui/qml/__init__.py +++ b/electrum/gui/qml/__init__.py @@ -36,6 +36,10 @@ if TYPE_CHECKING: from .qeapp import ElectrumQmlApplication +class UncaughtException(Exception): + pass + + class ElectrumGui(Logger): @profiler @@ -71,6 +75,9 @@ class ElectrumGui(Logger): self.timer.setInterval(500) # msec self.timer.timeout.connect(lambda: None) # periodically enter python scope + sys.excepthook = self.excepthook + threading.excepthook = self.texcepthook + # Initialize any QML plugins run_hook('init_qml', self) self.app.engine.load('electrum/gui/qml/components/main.qml') @@ -78,6 +85,18 @@ class ElectrumGui(Logger): def close(self): self.app.quit() + def excepthook(self, exc_type, exc_value, exc_tb): + tb = "".join(traceback.format_exception(exc_type, exc_value, exc_tb)) + self.logger.exception(tb) + self.app._valid = False + self.close() + + def texcepthook(self, arg): + tb = "".join(traceback.format_exception(arg.exc_type, arg.exc_value, arg.exc_tb)) + self.logger.exception(tb) + self.app._valid = False + self.close() + def main(self): if not self.app._valid: return