catch块没有捕获StackOverflowException

时间:2016-03-30 01:14:35

标签: c# exception stack-overflow

我最近看到一个有趣的函数代码返回第五个。

这就是它的样子:

namespace Rekursio {
   class Program {
        static void Main(string[] args) {
            Console.WriteLine(getFive());
            Console.ReadLine();
        }

        static int getFive() {
            try {
                return getFive();
            }
            catch (StackOverflowException e) {
                return 5;
            }        
        }
    }
}

我希望这个函数最后返回5。但是,在运行程序时,我被告知发生了未处理的StackOverflowException。

这怎么可能?处理StackOverflowException的每种情况都可以处理。

0 个答案:

没有答案
相关问题