How can I capture all exceptions from a wxPython application?

前端 未结 4 675
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-29 15:50

I\'m writing a little debug app for a bit of kit we\'re developing and I\'d like to roll it out to a few users to see if they can provoke any crashes. Does anyone know a way

4条回答
  •  梦谈多话
    2020-12-29 16:31

    For the exception handling, assuming your log file is opened as log:

    import sys
    import traceback
    
    def excepthook(type, value, tb):
        message = 'Uncaught exception:\n'
        message += ''.join(traceback.format_exception(type, value, tb))
        log.write(message)
    
    sys.excepthook = excepthook
    

提交回复
热议问题