未处理AccessViolationException 异常
AccessViolationException: 尝试读取或写入受保护的内存
原以为可以通过try catch屏蔽掉错误,不至于程序崩溃,但是,catch不起作用。不知道为什么?后来google才发现。问题:大致意思是Net能处理托管的Structured Error Handling (SEH)异常,
但是对于非托管Corrupted State Exceptions (CSE)异常却不能捕获,如果想捕获此种类型异常,需要在配置文件中,添加一下内容
<runtime>
<legacyCorruptedStateExceptionsPolicy enabled="true" />
</runtime>
在try catch中添加了AccessViolationException的捕获,代码如下:
private static bool BeginRunGP(IGPProcess process, ITrackCancel TC, Action<string> pMessage)
{
bool result = false;
try
{ if (m_geoprocessor == null)
{
m_geoprocessor = new Geoprocessor();
} m_geoprocessor.OverwriteOutput = true;
//m_geoprocessor.MessagesCreated += m_geoprocessor_MessagesCreated;
//showMessage("-------------------------------------------------------------------------------------------------------" + Environment.NewLine);
//showMessage(string.Format("开始时间:{0}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")) + Environment.NewLine);
if (pMessage != null)
{
pMessage("GP:" + process.ToolName);
}
IGeoProcessorResult2 geoProcessorResult = m_geoprocessor.Execute(process, null) as IGeoProcessorResult2;
if (geoProcessorResult != null && geoProcessorResult.Status == esriJobStatus.esriJobSucceeded)
{
result = true;
} if (geoProcessorResult != null)
{
for (int i = ; i < geoProcessorResult.MessageCount; i++)
{
string str = geoProcessorResult.GetMessages(i);
if (pMessage != null)
{
pMessage(str);
}
}
}
if (pMessage != null)
{
pMessage("GP:" + process.ToolName + " 结束");
}
result = true;
}
catch (System.AccessViolationException ex)
{ // AccessViolationException异常捕获
result = false;
}
catch (Exception ex) // COMException
{
result = false;
if (pMessage != null)
{
pMessage("GP:" + process.ToolName + " 错误");
pMessage(ex.Message);
LogClass.PubLog.ErrorFormat("GP:{0} 错误,错误原因是:{1}", process.ToolName, ex.Message);
}
LogClass.PubLog.ErrorFormat("GP:{0} 错误,错误原因是:{1}", process.ToolName, ex.Message);
}
finally
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
for (int i = ; i < m_geoprocessor.MessageCount; i++)
sb.AppendLine(m_geoprocessor.GetMessage(i)); }
return result;
}
下面是他的英文解释
http://msdn.microsoft.com/en-us/magazine/dd419661.aspx#id0070035
But there is hope. There are a few ways to get around this:
(1)Recompile as a .NET 3.5 assembly and run it in .NET 4.0.
(2)Add a line to your application's config file under the configuration/runtime element:<legacyCorruptedStateExceptionsPolicy enabled="true"/>
(3)Decorate the methods you want to catch these exceptions in with the HandleProcessCorruptedStateExceptions attribute. See http://msdn.microsoft.com/en-us/magazine/dd419661.aspx#id0070035 for details.
For more reference:http://connect.microsoft.com/VisualStudio/feedback/details/557105/unable-to-catch-accessviolationexception
未处理AccessViolationException 异常的更多相关文章
- 使用C#在VS中开发:未处理AccessViolationException “System.AccessViolationException”类型的未经处理的异常
未处理AccessViolationException: “System.AccessViolationException”类型的未经处理的异常在System.Data.dll中发生 其他信息:尝试读 ...
- 关于System.AccessViolationException异常
什么是AccessViolationException 试图读写受保护内存时引发的异常. 继承 Object Exception SystemException AccessViolationExce ...
- 关于SubSonic3.0未处理InvalidOperationException异常(关键字TOP附近有语法错误)的处理
早上在测试程序时,使用了Top这个属性,没想到马上抛出了个“未处理InvalidOperationException异常(关键字'TOP'附近有语法错误)”这个错误提示,见下图: 然后Debug一下, ...
- WPF捕获未处理的异常
WPF程序中,对于异常的捕获一般使用try/catch块.就像程序中的bug一样,很难保证程序中所有的异常都能够通过try/catch捕获.如果异常没有被捕获,轻则影响用户体验,严重时会导致数据丢失 ...
- C# WinForm捕获未处理的异常
using System; using System.Collections.Generic; using System.Windows.Forms; using System.IO; namespa ...
- Android中使用UncaughtExceptionHandler来处理未捕获的异常
原文在sparkyuan.me上.转载注明出处:http://sparkyuan.github.io/2016/03/28/使用UncaughtExceptionHandler来处理未捕获的异常/ 全 ...
- Error:(12, 64) java: 未报告的异常错误java.io.IOException; 必须对其进行捕获或声明以便抛出
Error:(12, 64) java: 未报告的异常错误java.io.IOException; 必须对其进行捕获或声明以便抛出 package com.test; import org.apach ...
- 编写高质量代码改善C#程序的157个建议——建议65:总是处理未捕获的异常
建议65:总是处理未捕获的异常 处理为捕获的异常是每个应用程序具备的基本功能,C#在APPDomain提供了UnhandledException事件来接收未捕获到的异常的通知.常见的应用如下: sta ...
- android 捕获未try的异常
1.Thread.UncaughtExceptionHandler java里有很多异常如:空指针异常,越界异常,数值转换异常,除0异常,数据库异常等等.如果自己没有try / catch 那么线程就 ...
随机推荐
- deepfake-faceswap第一篇论文-2016摘要
核心目标:给定一个人的单张图片A,另一个人的单张图片B,在保持姿势,面部表情,视线方向,发型和光照不变的条件下,将A图片中的人物换成B图片中的人物.2016年,文章[1]实现了这个目标: 德国的蒂宾根 ...
- 洛谷P1091 合唱队形
输入输出样例 输入样例#1: 8 186 186 150 200 160 130 197 220 输出样例#1: 4 此题意在先升后降子序列,单调递增子序列,单调递减子序列当中找到最长的一组序列. 因 ...
- VBA中查找并选定文字
如果从 Selection 对象访问 Find 对象,当找到搜索条件时,就会更改所选内容.下列示例选定下一个出现的“Hello”.如果到达文档结尾时仍未找到“Hello”,则停止搜索. With Se ...
- 2017年5月11日17:43:06 rabbitmq 消费者队列
从昨天开始发现个问题,一个接口在本地调用时大部分正常,一旦在生成者打一个断点调试,并且在promotion也打断点的时候会出现没有返回channel的异常,然后消费者就再也消费不了了 16:57:45 ...
- linux之正则
grep命令: -V 打印grep的版本号 -E 解释PATTERN作为扩展正则表达式,也就相当于使用egrep. -F 解释PATTERN作为固定字符串的列表,由换行符 ...
- python笔记3——字符串的操作
#Author:Wildwolf name="my name is wildwolf ," print(name.capitalize()) #首字母大写 print(name.c ...
- 关于Hibernate级联更新插入信息时提示主键不为空的问题“org.hibernate.StaleStateException: Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1 ”
org.hibernate.StaleStateException: Batch update returned unexpected row count from update: 0 actual ...
- Python字符串练习
1. 确定一个字符串中有多少个元音字母 def getCount(inputStr): return len([a for a in inputStr if a in "aeiou" ...
- Windows10 VS2017 C++编译Linux程序
#include <cstdio> #include <iostream> #include "unistd.h" using namespace std; ...
- css解决多行溢出显示省略号
多行溢出 仅作为记录方便查找 display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: number; /*n行溢 ...