异常堆栈跟踪是否可以为空?

问题描述 投票:12回答:3

我发现如果捕获到异常e,则e.innerException可能为null。

在任何可能的情况下,在catch块中e.StackTrace是否也可能为null?

try {

}
catch(Exception e)
{
//can e.StackTrace be null here?
}
c# exception
3个回答
17
投票

如果创建new Exception()但不抛出,则除DataMessage以外的所有属性都为空。


3
投票

证明在catch块中StackTrace可以为null的示例同样不容易显示:

public class DerpException : Exception
{
    public override string StackTrace
    {
        get { return null; }
    }
}

0
投票

如果使用,则可能将exception.StackTrace设为null使用try-catch的函数的[HandleProcessCorruptedStateExceptions]属性,在其中捕获异常,以及是否从本机代码引发异常。

[System.AccessViolationException]异常类型可能将StackTrace设为null。

不知道这是否与调试/发布版本和/或生成的pdb文件有关。我在Release版本中观察到这种崩溃。

© www.soinside.com 2019 - 2024. All rights reserved.