Link to home
Start Free TrialLog in
Avatar of AndyAinscow
AndyAinscowFlag for Switzerland

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");
  }
}
Avatar of rajeev_devin
rajeev_devin

Are you using WaitForSingleObject(...) for waiting.
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.
SOLUTION
Avatar of rajeev_devin
rajeev_devin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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).
Avatar of AndyAinscow

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'll have a look at those links as well.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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. )
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.
<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?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That looks very interesting, it opens up other possibilities.  I'll have to think about what I really do require.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Other things keep getting in the way - I'll try to get back to this next week.
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
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 :)
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.
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.