Logging All Exceptions in a pyqt4 app

logging, pyqt, python

Solution

You need to override `sys.excepthook`

def my_excepthook(type, value, tback):
    # log the exception here

    # then call the default handler
    sys.__excepthook__(type, value, tback) 

sys.excepthook = my_excepthook

Problem

What's the best way to log all of the exceptions in a pyqt4 application using the standard python logging api? I've tried wrapping exec_() in a try, except block, and logging the exceptions from that, but it only logs exceptions from the initialization of the app. As a temporary solution, I wrapped the most important methods in try, except blocks, but that can't be the only way to do it.

Original source