11

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.

Brad Zeis
  • 10,085
  • 5
  • 26
  • 20

1 Answers1

16

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
dF.
  • 74,139
  • 30
  • 130
  • 136