Skip to content

Commit

Permalink
do not crash with exception but display error message window
Browse files Browse the repository at this point in the history
  • Loading branch information
rgerum committed Feb 29, 2024
1 parent 76cd289 commit bfb73f8
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions saenopy/gui/gui_master.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,15 @@ def main(): # pragma: no cover
except (ImportError, RuntimeError):
pass

while True:
try:
res = app.exec_()
break
except Exception as err:
traceback.print_traceback(err)
QtWidgets.QMessageBox.critical(window, "Error", f"An Error occurred:\n{err}")
continue
from traceback import format_exception
def except_hook(type_, value, tb):
print(*format_exception(type_, value, tb), file=sys.stderr)
QtWidgets.QMessageBox.critical(window, "Error", f"An Error occurred:\n{type_.__name__}: {value}")
return

sys.excepthook = except_hook

res = app.exec_()
sys.exit(res)


Expand All @@ -226,13 +227,6 @@ def main(): # pragma: no cover
exec(code)
exit(0)


""" some magic to prevent PyQt5 from swallowing exceptions """
# Back up the reference to the exceptionhook
sys._excepthook = sys.excepthook
# Set the exception hook to our wrapping function
sys.excepthook = lambda *args: sys._excepthook(*args)

for arg in sys.argv:
if arg == "--demo":
import os
Expand Down

0 comments on commit bfb73f8

Please sign in to comment.