AndyAinscow
asked on
Trapping crash in another process
How would I go about starting another application and catching an unhandled exception / crash.
eg.
if(CreateProcess(.....))
{
try
{
while(processRunning)
{
//idle away - everything OK
}
cleanup and return
}
catch(ErrorInProcess)
{
msgbox("oh dear - it has crashed");
}
}
eg.
if(CreateProcess(.....))
{
try
{
while(processRunning)
{
//idle away - everything OK
}
cleanup and return
}
catch(ErrorInProcess)
{
msgbox("oh dear - it has crashed");
}
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Check this link for details
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/waitforsingleobject.asp
Finally, I hope you are using window (As your CreateProcess function tells that you are).
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/waitforsingleobject.asp
Finally, I hope you are using window (As your CreateProcess function tells that you are).
ASKER
Yes, it is a window based app ('normal' exe with a window that is). I'll give it a try later and get back.
I think you need CreateProcess with DEBUG_PROCESS flag, WaitForDebugEvent function and handling process exceptions:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/waitfordebugevent.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/writing_the_debugger_s_main_loop.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/waitfordebugevent.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/writing_the_debugger_s_main_loop.asp
ASKER
I'll have a look at those links as well.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Child process code should have:
try
{
...
//Code
...
}
catch(...)
{
GetLastError()
//Do some IPC calls to Parent Application
Exit Here...
}
Hope this makes my idea clear to you.
Best Regards,
DeepuAbrahamK
try
{
...
//Code
...
}
catch(...)
{
GetLastError()
//Do some IPC calls to Parent Application
Exit Here...
}
Hope this makes my idea clear to you.
Best Regards,
DeepuAbrahamK
ASKER
IPC - Good point.
At present this functionality may not even be required, should it be required it is initially just to trap the case of another app crashing, the why is a little less important at present. ( Often it would be nice to have PQR and XYZ but someone ultimately has to pay for it and wait for it to be coded. )
At present this functionality may not even be required, should it be required it is initially just to trap the case of another app crashing, the why is a little less important at present. ( Often it would be nice to have PQR and XYZ but someone ultimately has to pay for it and wait for it to be coded. )
If we can change code of child application, this is simple - just catch exception in the child, and there are 1000 ways to pass this information to parent. Interesting case is to do this for any child application, this depends on your requirements.
ASKER
<If we can change code of child application, this is simple - just catch exception in the child,>
You may have some knowledge that I don't. eg. MFC - SDI based app, where do I put ONE try..catch block to trap some exception anywhere in the app?
You may have some knowledge that I don't. eg. MFC - SDI based app, where do I put ONE try..catch block to trap some exception anywhere in the app?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That looks very interesting, it opens up other possibilities. I'll have to think about what I really do require.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Other things keep getting in the way - I'll try to get back to this next week.
ASKER
AlexFM, I've created another question specifically to award you points related to trapping an exception internally in an app. Not what I asked for here but a very useful alternative.
Please make a comment there.
https://www.experts-exchange.com/questions/22054603/Trapping-unhandled-exception.html
Please make a comment there.
https://www.experts-exchange.com/questions/22054603/Trapping-unhandled-exception.html
Andy, thank you, but "Points for" is not allowed now in EE. It's enough for me to know that my answer is OK. You can remove another question before some spammer didn't post some stupid link there :)
ASKER
It was an alternative that for me didn't match what I asked for here (hence I would have argued that it didn't go over the 500pts per question, because it was really a separate question).
I'll remove the other question and thank you for the information.
I'll remove the other question and thank you for the information.
ASKER
Awk - forget to hit submit before splitting points.
Thanks guys. At present I just want something simple so I haven't investigated the mini-debugger. All I have as a requirement at present is to see if the app being launched exits gracefully or not.
Thanks guys. At present I just want something simple so I haven't investigated the mini-debugger. All I have as a requirement at present is to see if the app being launched exits gracefully or not.
If yes then the return value of this function tells you about the status of the process.
Whether it terminated successfully, or some error creep in.