locked
How to catch unhandled exceptions in a process RRS feed

  • Question

  • Hi All,

    I have the following scenario. I have multiple process spaces and each process space has multiple app domains. Each appdomain in turn multiple classes each having multiple threads. Whenever an unhandled exception occurs in any of the app domains of a process space, I would like to handle it in a single place. I read the post http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/06097037-dc26-4169-88be-fb70161fb748 and found a way to handle uncaught exception within an app domain and also within a windows form. However, I would like to know how to handle uncaught exceptions across app domains but within a single process space. Please let me know if it is even possible and if yes then how?

    Thanks,

    Venkat

    • Edited by Venk K Thursday, October 4, 2012 9:48 AM
    Thursday, October 4, 2012 9:45 AM

Answers

  • Part-I

    Within a single process, you can know if the exceptions are not handled in a particular AppDomain using AppDomain.UnhandledException Event. Thus, you can chain all the AppDomain events to a same event handler.

    Part-II

    But, I don't think it is possible across processes because one process is not allowed to sneak inside another process space. Still, if you launch all those processes, you can handle this like:

    (1) Each process subscribes to UnhandledException events from all AppDomains in it through one common event handler in its process space.

    (2) Each common event handler in each process space can write to its own error stream.

    (3) If (1) and (2) are possible, then from the main process, you can read the error from the RedirectedStandardError stream of all those processes thus giving you the control of all AppDomains across all the processes.

    I don't know whether I offered you any helpful hints or confused you more. Sorry, if it is second feel please.

    • Edited by Rajesh_Kannan Thursday, October 4, 2012 10:47 AM
    • Proposed as answer by Bob Shen Friday, October 5, 2012 9:18 AM
    • Marked as answer by Venk K Sunday, October 7, 2012 9:51 PM
    Thursday, October 4, 2012 10:44 AM

All replies

  • Part-I

    Within a single process, you can know if the exceptions are not handled in a particular AppDomain using AppDomain.UnhandledException Event. Thus, you can chain all the AppDomain events to a same event handler.

    Part-II

    But, I don't think it is possible across processes because one process is not allowed to sneak inside another process space. Still, if you launch all those processes, you can handle this like:

    (1) Each process subscribes to UnhandledException events from all AppDomains in it through one common event handler in its process space.

    (2) Each common event handler in each process space can write to its own error stream.

    (3) If (1) and (2) are possible, then from the main process, you can read the error from the RedirectedStandardError stream of all those processes thus giving you the control of all AppDomains across all the processes.

    I don't know whether I offered you any helpful hints or confused you more. Sorry, if it is second feel please.

    • Edited by Rajesh_Kannan Thursday, October 4, 2012 10:47 AM
    • Proposed as answer by Bob Shen Friday, October 5, 2012 9:18 AM
    • Marked as answer by Venk K Sunday, October 7, 2012 9:51 PM
    Thursday, October 4, 2012 10:44 AM
  • Hi Rajesh,

    Thank you for your time and reply. Whatever suggestion you gave is extremely useful and helpful.

    Thanks,

    Venkat

    Thursday, October 4, 2012 11:25 AM