【发布时间】:2020-12-08 14:59:15
【问题描述】:
如何绕过 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,后者调用GetItemDetails。看到问题了吗? -
is there a better way to do this?如果你所说的“这个”是指导致堆栈溢出,那么不,你已经成功了! -
是的,这就是为什么我要问是否有办法绕过 stackoverflow 异常。我知道问题出在@JeroenMostert
-
您的问题中绝对没有任何信息。你想达到什么目的?逻辑在哪里?
标签: c# recursion model-view-controller stack-overflow