2********************************************************************************
3@file app_err_handler.py
4@brief Error handler to catch all unexpected exceptions to prevent application crashes
5********************************************************************************
13from typing
import Optional, Any, TYPE_CHECKING
14from types
import TracebackType
25log = logging.getLogger(__title__)
30 @brief Global exception handler. Overrides system exception hook to catch all unexpected errors.
32 exception_caught = SIGNAL(object)
34 def __init__(self, *args: Any, **kwargs: Any) ->
None:
35 log.debug(
"Initializing Exception Handler")
50 @brief Displays the error message box
51 @param s_log_msg : the error message to be displayed in details section
55 if (APPLICATION
is not None)
and (APPLICATION.instance()
is not None):
57 l_close_text = L_CLOSE
63 text = L_UNEXP_ERROR[0]
64 repair_text = L_REPAIR[0]
65 close_text = l_close_text[0]
67 "Error", f
"{text}\t\t\t\t",
69 btn_special=repair_text,
70 detailed_text=s_log_msg,
79 log.error(
"Can't show Exception Display - No QApplication instance available.")
81 def exception_hook(self, exc_type: type[BaseException], exc_value: BaseException, exc_traceback: Optional[TracebackType] =
None) ->
None:
83 @brief Custom exception hook. It is triggered each time an uncaught exception occurs.
84 @param exc_type : exception type
85 @param exc_value : exception value
86 @param exc_traceback : exception traceback
88 if issubclass(exc_type, KeyboardInterrupt):
90 sys.__excepthook__(exc_type, exc_value, exc_traceback)
92 log_msg =
"\n".join([f
"{exc_type.__name__}: {exc_value}",
93 "".join(traceback.format_tb(exc_traceback))])
101 @brief Sets the main window controller in order to unblock the UI after a critical exception is caught.
102 @param main_window_controller : main window controller
Global exception handler.
None __init__(self, *Any args, **Any kwargs)
None set_main_window_controller(self, "MainWindow" main_window_controller)
Sets the main window controller in order to unblock the UI after a critical exception is caught.
None exception_hook(self, type[BaseException] exc_type, BaseException exc_value, Optional[TracebackType] exc_traceback=None)
Custom exception hook.