[英]System.StackOverflowException C#
How can I bypass a stackoverflow exception or is there a better way to do this?如何绕过 stackoverflow 异常或者有更好的方法来做到这一点? Any help is greatly appreciated!
任何帮助是极大的赞赏!
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 and GetData methods are mutually called, it causes the "infinite" loop with stack allocations for each call, unfortunatelly stack size isn't infinite;) GetItemDetails 和 GetData 方法是相互调用的,它会导致“无限”循环,每次调用都会分配堆栈,不幸的是堆栈大小不是无限的;)
See more details here: https://www.dotnetperls.com/stackoverflowexception在此处查看更多详细信息: https://www.dotnetperls.com/stackoverflowexception
StackOverflowException can't be bypased, it can't be catched, it must be avoided. StackOverflowException 不能被绕过,不能被捕获,必须避免。 It exists to protect .NET runtime from fatal crash.
它的存在是为了保护 .NET 运行时免受致命崩溃。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.