exception_handler#
Centralised GUI exception handling for ClearMap.
Usage#
From any tab or controller:
from ClearMap.gui.exception_handler import handle_exception
try:
worker.run()
except ClearMapException as exc:
action = handle_exception(exc, parent=self.main_window)
if action == 'retry':
...
elif action == 'reset_workspace':
self.main_window.trigger_workspace_reset()
At application startup:
from ClearMap.gui.exception_handler import install_global_handler
install_global_handler(app, parent_getter=lambda: gui.window)
- class ExceptionDialog(exc: ClearMapException, parent: QWidget | None = None, context: str = '')[source]#
Bases:
QDialogModal dialog that presents a
ClearMapExceptionto the user. Afterexec_(), readchosen_actionfor the action string corresponding to theRecoveryOptionthe user clicked.
- handle_exception(exc: Exception, parent: QWidget | None = None, context: str = '') str[source]#
Show an exception dialog and return the chosen action string. For non-ClearMap exceptions a generic FATAL dialog is shown.
- Parameters:
exc – The exception to present.
parent – Parent widget for the dialog (centres it on the parent window).
context – Optional extra line (e.g.
"CellCounterTab.detect_cells").
Returns
- str
The
actionfield of the chosenRecoveryOption, e.g.'dismiss','retry','reset_workspace','close'.
- install_global_handler(app: QApplication, parent_getter: Callable[[], ~PyQt5.QtWidgets.QWidget | None]=<function <lambda>>, on_reset: Callable[[], None] | None=None, on_close: Callable[[], None] | None=None) None[source]#
Install a
sys.excepthookthat showshandle_exception().- Parameters:
app – The running QApplication.
parent_getter – Callable returning the current main window (or
None).on_reset – Callback for the
'reset_workspace'action. WhenNone, falls back toapp.quit().on_close – Callback for the
'close'action. WhenNone, callsapp.quit().