未验证 提交 20643918 编写于 作者: J Jared Parsons 提交者: GitHub

Merge pull request #42602 from jaredpar/debug-failfast

Diagnostics for FailFast
......@@ -32,12 +32,40 @@ internal static void OnFatalException(Exception exception)
{
exception = aggregate.InnerExceptions[0];
}
#endif
DumpStackTrace(exception);
Environment.FailFast(exception.ToString(), exception);
throw ExceptionUtilities.Unreachable; // to satisfy [DoesNotReturn]
}
/// <summary>
/// Dumps the stack trace of the exception and the handler to the console. This is useful
/// for debugging unit tests that hit a fatal exception
/// </summary>
[Conditional("DEBUG")]
private static void DumpStackTrace(Exception exception)
{
Console.WriteLine("Dumping info before call to failfast");
Console.WriteLine("Exception info");
for (Exception? current = exception; current is object; current = current!.InnerException)
{
Console.WriteLine(current.Message);
Console.WriteLine(current.StackTrace);
current = current.InnerException;
}
#if !NET20 && !NETSTANDARD1_3
Console.WriteLine("Stack trace of handler");
var stackTrace = new StackTrace();
Console.WriteLine(stackTrace.ToString());
#endif
Console.Out.Flush();
}
/// <summary>
/// Checks for the given <paramref name="condition"/>; if the <paramref name="condition"/> is <c>true</c>,
/// immediately terminates the process without running any pending <c>finally</c> blocks or finalizers
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册