由于重复调用函数而导致堆栈溢出异常 [英] Stack overflow exception due to repetitive calling of a function

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

问题描述

我正在创建一个带有文本框的网页,并在其旁边添加按钮。在文本框中输入值并单击添加按钮时,该值将添加到数据库中,我使用列表完成了该操作。我还创建了一个以textbox值作为参数的函数,我给出了一个返回Save以返回值。当我在函数中放置一个断点并执行程序并输入值然后单击add时,它会移动到函数并重复调用函数并导致堆栈溢出异常,但是当我将光标放在return语句上时输入的值已显示。任何人都可以帮我解决这个问题。

I am creating a webpage with a textbox and add button by its side. As enter values in the textbox and click on the add button the value will be added in the database, which I have done using "List". I have also created a function with the textbox value as its parameter and I have give a return Save to return the value. As I place a break point in the function and execute the program and enter the values and then click on add, it moves to the function and the function is repetitively called and results in stack overflow exception but as I place my cursor on the return statement the entered value is been displayed. Can anyone help me out to fix this issue.

public bool Save(string NewsItems)
       {
           return Save(NewsTickerItems);
       }







List<SqlParameter> parameters = new List<SqlParameter>();
 parameters.Add(new SqlParameter("@NewsItems", NewsItems));

推荐答案

递归:参见递归。



如果你拿一张纸,并在两边写上请翻身,你可以把它交给一个白痴,让他们逗乐数小时。任何更明亮的人都会看到两个,也许是三个方面,他们的筹码将耗尽,他们会厌恶和无聊地放下它。

这就是这里发生的事情:每次调用Save函数时,返回地址被压入堆栈(因此它知道在Save完成时返回的位置),然后再次调用Save函数。这会导致返回地址被压入堆栈(因此它知道在Save完成时返回的位置),然后再次调用Save函数。这导致...



直到堆栈耗尽并且你得到一个例外。并且您的网站崩溃了。
Recursion: see "Recursion".

If you take a sheet of paper, and write "please turn over" on both sides, you can hand it to an idiot and keep them amused for hours. Anyone brighter will look at two, perhaps three sides and their stack will run out and they will put it down in disgust and boredom.
That's what's happening here: every time you call the Save function, the return address is pushed onto the stack (so it knows where to come back to when Save finishes), and it then calls the Save function again. This causes the return address to be pushed onto the stack (so it knows where to come back to when Save finishes), and it then calls the Save function again. This causes...

Until the stack runs out and you get an exception. And your site crashes.


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

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