.NET 中的 StackOverflowException [英] StackOverflowException in .NET
问题描述
在 .NET 中遇到一些 StackOverflowExceptions 后,我注意到它们完全绕过了 .NET 提供的未处理的异常处理程序(Application.ThreadException/AppDomain.UnhandledException).这非常令人不安,因为我们在这些异常处理程序中有关键的清理代码.
After hitting a few StackOverflowExceptions in .NET I noticed they completely bypass the unhandled exception handlers that .NET offers (Application.ThreadException / AppDomain.UnhandledException). This is very disturbing since we have critical cleanup code in those exception handlers.
有什么办法可以解决这个问题吗?
Is there any way to overcome this?
推荐答案
不是真的;堆栈溢出或内存不足异常发生在 CLR 本身意味着某些事情发生了严重错误(当我一直是个笨蛋并创建了递归属性时,我通常会得到它).
Not really; a stack overflow, or an out of memory exception happens within the CLR itself means something has gone critically wrong (I usually get it when I've been a dumbass and created a recursive property).
当此状态发生时,CLR 无法分配新的函数调用或内存以使其能够调用异常处理程序;这是一个我们必须现在"的场景.
When this state occurs there is no way for the CLR to allocate new function calls or memory to enable it to call into the exception handlers; it's a "we must halt now" scenario.
但是,如果您自己抛出异常,您的异常处理程序将被调用.
If, however, you throw the exception yourself your exception handlers will be called.
这篇关于.NET 中的 StackOverflowException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!