locked
How to capture the Unhandled StackOverFlow in Ver4.6.1 .NET application RRS feed

  • Question

  • Hi guys,

    I want to capture the above exception, but find the following method doesn't work. 

    Any other way to implement our requirement?

    Not consider Adplus because the app is in the client/production environment. 

            private void Window_Loaded(object sender, RoutedEventArgs e)
            {
                //Application.Current.DispatcherUnhandledException += Current_DispatcherUnhandledException;
                AppDomain currentDomain = AppDomain.CurrentDomain;
                currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler);
            }

            static void MyHandler(object sender, UnhandledExceptionEventArgs args)
            {
                Exception e = (Exception)args.ExceptionObject;
                Console.WriteLine("MyHandler caught : " + e.Message);
                Console.WriteLine("Runtime terminating: {0}", args.IsTerminating);
            }

    Thanks always,


    Best regards,
    Riquel

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    • Edited by Riquel I'm Tuesday, June 27, 2017 6:34 PM
    Tuesday, June 27, 2017 1:41 PM

Answers

  • Did you already find that a series of exceptions cannot be always caught? For example: https://blogs.msdn.microsoft.com/jaredpar/2008/10/22/when-can-you-catch-a-stackoverflowexception/. This kind of situations performs a critical alteration of engine, which prevents further execution of the code that requires a valid stack, including your MyHandler.

    According to articles, maybe you can limit the level of recursions, or check the available stack space before continuing the recursions.

    Check if this exception adds relevant messages to Windows Events. Use the Event Viewer tool.

    • Marked as answer by Riquel I'm Friday, June 30, 2017 5:13 PM
    Tuesday, June 27, 2017 9:19 PM

All replies

  • Did you already find that a series of exceptions cannot be always caught? For example: https://blogs.msdn.microsoft.com/jaredpar/2008/10/22/when-can-you-catch-a-stackoverflowexception/. This kind of situations performs a critical alteration of engine, which prevents further execution of the code that requires a valid stack, including your MyHandler.

    According to articles, maybe you can limit the level of recursions, or check the available stack space before continuing the recursions.

    Check if this exception adds relevant messages to Windows Events. Use the Event Viewer tool.

    • Marked as answer by Riquel I'm Friday, June 30, 2017 5:13 PM
    Tuesday, June 27, 2017 9:19 PM
  • Hi Viorel,

    Thanks for kind help. I understood that the coding can not catch these severe exceptions. 

    Is there any way to configure any Microsoft tools (Windows built-in) to automatically log these kind of unhandled exceptions which can't be captured by try/catch block?

    Any idea?

    Thanks,


    Best regards,
    Riquel

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, June 28, 2017 2:55 PM
  • The crash should be reported to the Windows event log but it will be a little light on details. I believe there is a registry option somewhere that causes unhanded exceptions to be reported to the event log with a full stack trace, but I don't recall the name.
    Wednesday, June 28, 2017 10:02 PM