C# cannot catch StackOverflowException or see where it happened

This question already has an answer here:

  • C# catch a stack overflow exception 9 answers

  • You are not allowed to catch a real stack overflow exception, which is why it won't work.

    Also see this discussion.

    I can't answer your second question, other than to say "the program's really messed-up".

    For your third question: Because it's running in a separate thread the amount of code that it has run will vary depending on when you break the program. I think the only way you'll be able to get to the bottom of this is through some tedious line-by-line debugging, or lots of Debug.WriteLine().


    1) Starting with the .NET Framework version 2.0, a StackOverflowException object cannot be caught by a try-catch block and the corresponding process is terminated by default. Consequently, users are advised to write their code to detect and prevent a stack overflow. For example, if your application depends on recursion, use a counter or a state condition to terminate the recursive loop. Note that an application that hosts the common language runtime (CLR) can specify that the CLR unload the application domain where the stack overflow exception occurs and let the corresponding process continue. For more information, see ICLRPolicyManager Interface and Hosting Overview. (http://msdn.microsoft.com/en-us/library/system.stackoverflowexception.aspx)

    链接地址: http://www.djcxy.com/p/80762.html

    上一篇: 如何记录StackOverflowException的堆栈跟踪?

    下一篇: C#无法捕获StackOverflowException或查看它发生的位置