Python, tkinter and imported classes: logging uncaught exceptions Python, tkinter and imported classes: logging uncaught exceptions tkinter tkinter

Python, tkinter and imported classes: logging uncaught exceptions


Aha, I have found the issue.The excepthook that is installed in the aforementioned way is only working on a higher level. I figured that out when I noticed that the exceptions that my class was throwing were still logging in the console while a keyboard interrupt did log in the file as I wanted.

Next thing I found was that you can have similar issues when using threads in Python. The main thread would still log as wanted but the exceptions in the other thread would not. Then I figured that classes can override my overriding of what to do with exceptions. Since all of my code is running in the tkinter mainloop I might need to tell that bit to do what I want it to do. This insight led me to this SO answer and with one line of code everything was fixed, all the way at the end of the main class:

# Run the approot = tk.Tk()root.report_callback_exception = exception_handler # this here.app = ExceptMain(root)root.mainloop()