堆栈溢出异常 [英] Stack Overflow Exception

查看:86
本文介绍了堆栈溢出异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





当我尝试创建表单的对象时,我在运行期间遇到了上述错误。

未处理的异常Test.exe中出现'System.StackOverflowException'类型

  public  Form5 fg =  new  Form5(); 

解决方案

当您有直接或间接递归时,通常会发生堆栈溢出错误:

所以看看你的Form5构造函数,看看它的作用。如果它没有做太多,那么开始查看Form5字段和属性 - 在某个地方,类调用的方法会导致再次创建Form5实例,或者属性setter导致属性值被更改。 br />


如果不明显,那么在构造函数的第一行放一个断点 - 如果它被命中,那么你需要开始单步执行构造函数代码来寻找递归,如果不是,那么它可能正在进行字段初始化。



我们不能为你做到这一点 - 我们无法运行你的代码!

Hi,

When I try to create object of a form, I got the above error during run.
An unhandled exception of type 'System.StackOverflowException' occurred in Test.exe

public Form5 fg = new Form5();

解决方案

A stack overflow error normally occurs when you have direct or indirect recursion:
So look at your Form5 constructor and see what it does. If it doesn't do much, then start looking at the Form5 fields and properties - somewhere, the class is calling a method that causes the Form5 instance to be created again, or a property setter is causing the property value to be changed.

If it's not obvious, then put a breakpoint on the first line of the constructor - if it gets hit, then you need to start stepping through the constructor code looking for the recursion, if it isn't, then it's probably a field initialisation that is doing it.

We can't do that for you - we can't run your code!


这篇关于堆栈溢出异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆