How to programmatically detect an application has crashed in Windows?

时光毁灭记忆、已成空白 提交于 2021-02-10 16:12:54

问题


I am running a Python script that launches a number of apps. I need a way to detect if the app that's launched has crashed. Some apps have internal crash handling

How can I detect the crash?


回答1:


If they have internal crash handling, it's not possible to detect. The application will handle the error and exit normally. You can't even detect this if you would attach yourself as a debugger.

The reason is exception dispatching (MSDN):

  1. the debugger gets informed about an exception. This is called the first chance exception. However, this might be "normal", e.g. FileNotFound, which is expected by the application.
  2. Windows is looking for someone who wants to handle the exception. This can be the except block of a Python application, a catch block in C# or C++ or even a general "unhandled exception handler".
  3. If nobody wanted to handle the application, the debugger gets informed again. This time, the exception is marked as a second chance exception. This means that the application will crash next.

You're looking to become informed as part of step 3, however, the application has already stopped the process in step 2.



来源:https://stackoverflow.com/questions/47343331/how-to-programmatically-detect-an-application-has-crashed-in-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!