locked
Catch unhandled exceptions in child processes RRS feed

  • Question

  • Does anyone know of any way to catch unhandled exceptions in a child process created by your application using a System.Diagnostics.Process?  My application calls some other tool applications as child processes but occasionally these tools get a fatal exception and the 'do you wish to debug' dialog pops up this hangs my application until the users clicks yes or no in the dialog.  Is there any way to handle the exception of the process in code and close the tool quietly after the exception?

    Cheers,

    Daniel
    Monday, August 1, 2005 10:58 AM

Answers

  • Unfortunately, you cannot catch exceptions in child processes. If you do not have control over the tools' code, there is not much that you can really do. If you can make changes to the tools' code, you should add exception handling code to catch these exceptions and report to the user or calling app appropriately. Appropriate exception handling code for Windows Forms includes a try/catch around Main(), a handler for Application.ThreadException, and a handler for AppDomain.CurrentDomain.UnhandledException. For Console apps, you need a try/catch around Main() and a handler for AppDomain.CurrentDomain.UnhandledException.
    Tuesday, August 2, 2005 7:02 AM

All replies

  • Unfortunately, you cannot catch exceptions in child processes. If you do not have control over the tools' code, there is not much that you can really do. If you can make changes to the tools' code, you should add exception handling code to catch these exceptions and report to the user or calling app appropriately. Appropriate exception handling code for Windows Forms includes a try/catch around Main(), a handler for Application.ThreadException, and a handler for AppDomain.CurrentDomain.UnhandledException. For Console apps, you need a try/catch around Main() and a handler for AppDomain.CurrentDomain.UnhandledException.
    Tuesday, August 2, 2005 7:02 AM
  • I was starting to suspect it was not possible to catch or detect exceptions in child processes thanks for confirming it.
    Tuesday, August 2, 2005 9:11 AM