mafw.steering_gui.utils.exception_handling

GUI exception handling utilities for the steering application.

Author:

Bulgheroni Antonio (antonio.bulgheroni@ec.europa.eu)

Description:

Provide a reusable PySide6-compatible exception handler that surfaces errors from the GUI and worker threads via dialog boxes.

Functions

get_thread_exception_handler()

Get or create the global thread exception handler.

install_exception_handler()

Install a global exception handler to show errors in a dialog box.

show_exception_dialog(exception_type, ...)

Display an exception in a message box dialog.

Classes

ThreadExceptionHandler([display_callback])

Handle exceptions raised in non-GUI threads and forward them to the GUI.

class mafw.steering_gui.utils.exception_handling.ThreadExceptionHandler(display_callback: Callable[[type[BaseException] | None, BaseException | None, TracebackType | None], Any] | None = None)[source]

Bases: QObject

Handle exceptions raised in non-GUI threads and forward them to the GUI.

Initialize the handler and connect its signal to a display callback.

Parameters:

display_callback (Callable[[type[BaseException] | None, BaseException | None, TracebackType | None], Any]) – Optional callable to show the exception details.

handle_exception(exc_type: type[BaseException] | None, exc_value: BaseException | None, exc_traceback: TracebackType | None) None[source]

Emit an exception signal so it can be shown on the GUI thread.

Parameters:
  • exc_type (Type[BaseException] | None) – Type of the exception.

  • exc_value (BaseException | None) – The exception instance.

  • exc_traceback (TracebackType | None) – Traceback object.

mafw.steering_gui.utils.exception_handling.get_thread_exception_handler() ThreadExceptionHandler[source]

Get or create the global thread exception handler.

Returns:

The global thread exception handler instance.

Return type:

ThreadExceptionHandler

mafw.steering_gui.utils.exception_handling.install_exception_handler() Callable[[type[BaseException], BaseException, TracebackType | None], Any][source]

Install a global exception handler to show errors in a dialog box.

Returns:

The original sys.excepthook implementation.

Return type:

Callable[[Type[BaseException], BaseException, TracebackType | None], Any]

mafw.steering_gui.utils.exception_handling.show_exception_dialog(exception_type: type[BaseException] | None, exception_value: BaseException | None, exception_traceback: TracebackType | None) None[source]

Display an exception in a message box dialog.

Parameters:
  • exception_type (Type[BaseException] | None) – Type of the exception.

  • exception_value (BaseException | None) – The exception instance.

  • exception_traceback (TracebackType | None) – Traceback object.

mafw.steering_gui.utils.exception_handling._DisplayCallback

Type alias for exception display callbacks.

alias of Callable[[type[BaseException] | None, BaseException | None, TracebackType | None], Any]

mafw.steering_gui.utils.exception_handling._thread_exception_handler: ThreadExceptionHandler | None = None

Global instance of the thread exception handler.