如何解决System.StackOverflowException C#
如何绕过stackoverflow异常,或者有更好的方法呢?任何帮助将不胜感激!
public MetricItemDetail GetData(int itemId,int itemTwoId)
{
//some of my code goes here..
try
{
return new Class
{
Value = GetItemDetails(itemId,itemIdTwo)
};
}
catch (Exception e)
{
Console.WriteLine("{0} Exception caught.",e);
return new Class();
}
}
public double GetItemDetails(int itemId,int itemTwoId)
{
var currentValue = GetData(itemId,itemTwoId); // The problem is here..this is where I get the stackoverflow exception
}
解决方法
GetItemDetails和GetData方法相互调用,它会导致每次调用具有堆栈分配的“无限”循环,不幸的是堆栈大小不是无限的;)
在此处查看更多详细信息:https://www.dotnetperls.com/stackoverflowexception
StackOverflowException无法被粘贴,无法被捕获,必须避免。它的存在是为了保护.NET运行时免受致命崩溃的影响。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。