Calling a hook function every time an Exception is raised

后端 未结 4 1783
情深已故
情深已故 2020-11-30 10:05

Let\'s say I want to be able to log to file every time any exception is raised, anywhere in my program. I don\'t want to modify any existing code.

Of course, this c

4条回答
  •  眼角桃花
    2020-11-30 10:49

    If you want to log uncaught exceptions, just use sys.excepthook.

    I'm not sure I see the value of logging all raised exceptions, since lots of libraries will raise/catch exceptions internally for things you probably won't care about.

提交回复
热议问题