首页 > 其他分享 >System.AccessViolationException 异常

System.AccessViolationException 异常

时间:2022-12-13 14:45:01浏览次数:34  
标签:捕获 System State 异常 破坏性 AccessViolationException

winfrom的程序遇到System.AccessViolationException  异常后提示异常后自动关闭了,后期在异常点使用try...catch未捕获到异常。

最后查询资料发现是:在.NET 4.0之后,CLR将会区别出一些异常(都是SEH异常),将这些异常标识为破坏性异常(Corrupted State Exception)。针对这些异常,CLR的catch块不会捕捉这些异常

若是需要捕获这种破坏性异常(Corrupted State Exception)可以使用以下两种方式

1.捕获整个程序的破坏性异常

在App.config中的runtime字节中增加<legacyCorruptedStateExceptionsPolicy enabled="true" />

 

 

 2.捕获某个函数的破坏性异常在函数前增加属性[System.Runtime.ExceptionServices.HandleProcessCorruptedStateExceptions]

 

 

注:具体的解释参考https://www.cnblogs.com/profession/p/13285371.html

标签:捕获,System,State,异常,破坏性,AccessViolationException
From: https://www.cnblogs.com/sugarwxx/p/16978729.html

相关文章