问题描述
我什至不知道是什么导致了我的应用程序。它是什么?我创建了一个类的新实例(该类位于另一个文件中),但是在我第一次调用一个方法时,它引发了StackOverFlow异常。
I dont even know what caused it in my application. What is it? I created a new instance of a class (the class was in another file), but at the first time I call a method it throws a StackOverFlow exception.
我认为从逻辑上讲,如果有人投票反对Jon Skeet,就会抛出stackoverflow异常。
The only thing that I think would logically throw a stackoverflow exception would be if someone downvoted Jon Skeet.
但是现在认真的是什么?通过在与第一个类相同的文件中创建另一个类并使用该类为我调用方法来解决该问题。
But seriously now, what is it? I got around it by creating another class in the same file as the first class and using that to call the methods for me.
推荐答案
通常,堆栈溢出异常是由递归算法引起的,其中递归深度超过了(通常)固定堆栈限制。这通常是算法错误的结果,但也可能是由于您将算法应用的数据结构过于深造成的。
As a general rule, a stack overflow exception is caused by a recursive algorithm where the depth of recursion has exceeded the (typically) fixed stack limit. This is usually a result of a bug in the algorithm, but it may also be caused by the data structure you are applying the algorithm to being too "deep".
function int length(list l) {
if (empty(l)) {
return 0;
} else {
return 1 + length(l); // should be 'return 1 + length(tail(l));
}
}
任何非空列表的通话时长将为典型编程语言中的堆栈溢出。但是,即使您纠正了该错误,调用长列表方法也可能会导致堆栈溢出。
Calling length for any non-empty list will give a stack overflow in a typical programming language. But even if you correct the bug, calling the method for a long list is likely to cause a stack overflow.
(例外情况是您使用一种语言时...或更严格地说是支持尾部递归优化的编译器。)
(The exception is when you use a language ... or more strictly a compiler ... that supports tail recursion optimization.)
这篇关于vb.net中的StackOverFlow异常是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!