【发布时间】:2016-09-14 17:13:07
【问题描述】:
完美的 StackOverflow 问题终于来了....
如何捕获 StackOverflow 异常!
似乎在 .NET Core 中 StackOverflowException 不可用:
如果我运行这段代码:
using System;
namespace PlayGround.Core.Console
{
public class Program
{
public static void Main(string[] args)
{
try
{
DoSomething();
}
catch(Exception e)
{
System.Console.WriteLine("Bugger");
}
}
private static void DoSomething()
{
DoSomething();
}
}
}
我明白了:
您可以看到我的异常处理程序没有运行。那么如何在 .NET Core 中捕获这个异常呢?
2017 年 9 月 15 日编辑: 在 .NET Core 2.0 中现在有一个 StackOverflowException 类,但它实际上仍然没有捕获 stackoverflow 异常。
【问题讨论】:
-
@Technetium,不是重复的,因为在 .NET 中可以捕获这些异常,并且可以在 try/catch 中访问类本身。 .NET Core 是完全不同的动物。
-
确实,你是正确的@joshcomley。这很奇怪。您可以在
System下其他所有内容旁边的源代码中看到它。 github.com/dotnet/corefx/blob/master/src/mscorlib/ref/Compat/… -
@LexLi 好主意,现在已经这样做了:github.com/dotnet/coreclr/issues/14010
标签: exception exception-handling .net-core