尽管有HandleProcessCorruptedStateExceptions,仍未捕获AccessViolationException

时间:2016-10-18 14:22:20

标签: c# visual-studio debugging exception access-violation

我很困惑。 AccessViolationException由第三方库随机引发。它可以安全地被忽略,所以我将调用方法包装在建议here[HandleProcessCorruptedStateExceptions]属性中。

但是,我仍然看到如下所示引发异常: enter image description here

我正在使用.NET Framework 4.6.2和Visual Studio 2015 Update 3.我可以错过什么?

1 个答案:

答案 0 :(得分:1)

您忘记在try/catch周围插入table.Start()

[HandleProcessCorruptedStateExceptions]肯定需要try/catch来抓住AccessViolationException

所以你的代码应该是:

[HandleProcessCorruptedStateExceptions]
private static void StartTable(Table table) {
    try
    {
        table.Start();
    }
    catch (AccessViolationException)
    {
        // Ignore
    }
}

您可以查看herehere以获取参考资料。