When I was developing programs with PyGTK, one of my favourite little things to include to make life better for users was a drop-in helper named
gtkexcepthook.py which adds a GUI traceback handler for uncaught exceptions.
Well, I finally got around to porting it to PyQt 5.x for one of my more recent projects, and I’ve named it
qtexcepthook.py. (what else?)
The original was under “The license is whatever you want.” terms, so, out of respect of the original author’s intentions, I’m releasing the port into the public domain rather than putting it under a permissive license (eg. MIT) like I usually would for a something like this (simple, and I want everyone to use it).
I’ve also done a lot of refactoring to make it more maintainable.
Admittedly, there’s still a little more I’d like to do, and it doesn’t have any automated tests yet, but manual testing seems to give it a clean bill of health and I added a fallback so that, if the most complicated code does contain a bug and that bug triggers an exception, it’ll fall back to a more primitive exception-formatting mechanism (plus a traceback for the more advanced code) rather than failing entirely.
Finally (and, from a user’s perspective, most importantly), I took the liberty of splitting out the old email-based option for one-click reporting of bugs into a callback so you can swap in something more modern (eg. like an HTTP POST) if you so choose.
The code contains a working
if __name__ == '__main__' example which can be switched between no callback and
localhost-based e-mail reporting just by swapping some comments, so it should be pretty self-explanatory. Enjoy. 🙂