在进行arcgis的GP操作时,当操作栅格图像的拼接时,报错:

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;
}

下面是他的英文解释

 
In .NET 4.0, the runtime handles certain exceptions raised as Windows Structured Error Handling (SEH) errors as indicators of Corrupted State. 
These Corrupted State Exceptions (CSE) are not allowed to be caught by your standard managed code. I won't get into the why's or how's here. Read this article about CSE's in the .NET 4.0 Framework:

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 异常的更多相关文章

  1. 使用C#在VS中开发:未处理AccessViolationException “System.AccessViolationException”类型的未经处理的异常

    未处理AccessViolationException: “System.AccessViolationException”类型的未经处理的异常在System.Data.dll中发生 其他信息:尝试读 ...

  2. 关于System.AccessViolationException异常

    什么是AccessViolationException 试图读写受保护内存时引发的异常. 继承 Object Exception SystemException AccessViolationExce ...

  3. 关于SubSonic3.0未处理InvalidOperationException异常(关键字TOP附近有语法错误)的处理

    早上在测试程序时,使用了Top这个属性,没想到马上抛出了个“未处理InvalidOperationException异常(关键字'TOP'附近有语法错误)”这个错误提示,见下图: 然后Debug一下, ...

  4. WPF捕获未处理的异常

     WPF程序中,对于异常的捕获一般使用try/catch块.就像程序中的bug一样,很难保证程序中所有的异常都能够通过try/catch捕获.如果异常没有被捕获,轻则影响用户体验,严重时会导致数据丢失 ...

  5. C# WinForm捕获未处理的异常

    using System; using System.Collections.Generic; using System.Windows.Forms; using System.IO; namespa ...

  6. Android中使用UncaughtExceptionHandler来处理未捕获的异常

    原文在sparkyuan.me上.转载注明出处:http://sparkyuan.github.io/2016/03/28/使用UncaughtExceptionHandler来处理未捕获的异常/ 全 ...

  7. Error:(12, 64) java: 未报告的异常错误java.io.IOException; 必须对其进行捕获或声明以便抛出

    Error:(12, 64) java: 未报告的异常错误java.io.IOException; 必须对其进行捕获或声明以便抛出 package com.test; import org.apach ...

  8. 编写高质量代码改善C#程序的157个建议——建议65:总是处理未捕获的异常

    建议65:总是处理未捕获的异常 处理为捕获的异常是每个应用程序具备的基本功能,C#在APPDomain提供了UnhandledException事件来接收未捕获到的异常的通知.常见的应用如下: sta ...

  9. android 捕获未try的异常

    1.Thread.UncaughtExceptionHandler java里有很多异常如:空指针异常,越界异常,数值转换异常,除0异常,数据库异常等等.如果自己没有try / catch 那么线程就 ...

随机推荐

  1. Python第三章(北理国家精品课 嵩天等)

    一.数字类型及其操作 整数:pow(x,y),想算多大,就算多大:以0b或0B开头表示二进制:以0o或0O开头表示八进制:以0x或0X开头表示十六进制. 浮点数:取值范围-10^308至10^308, ...

  2. .Net Core+Angular6 学习 第三部分(从api获取data)

    . 现在开始需要集成angular6到VS项目中 1.1 打开Startup.cs文件, 在ConfigureServices方法中配置angular files的目录. 1.2 在Configure ...

  3. centos 6.5 安装 tomcat8 及性能优化_虚拟主机

    Tomcat服务器是一个免费的开放源代码的Web应用服务器,属于轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开发和调试JSP程序的首选. Tomcat和Nginx.Apa ...

  4. 东芝L10安装Centos5.5

    为什么安装5.5:因为高版本的需要PAE设定但是老电脑不支持,偶又不想重新编译内核,so... 1.  安装之前需要把电脑格式化(我是整机安装Linux),否则会报not enough space l ...

  5. mybatis进行一对多时发现的问题总结

    1.定义一对多xml文件时,所有的resultMap中的column的值一定不要重复,否则mybatis会发生错误,如果有重名,定义别名,column中的名字一定要与查询出的名字一致,如: 52行的别 ...

  6. JAVAEE期末项目------文章发布系统

    项目文档和代码的GitHub地址:https://github.com/xiangbaobaojojo/- 1.项目介绍 (计科四班  蔡春燕 20150141401)和我 陈香宇(计科四班  201 ...

  7. 从网络上获取图片,并写入excel文件

    package com.weChat.utils; import com.manage.utils.DateUtil;import com.manage.utils.MD5Util;import or ...

  8. idea 引入web、配制tomcat

    引入web包: https://www.cnblogs.com/chenloveslife/p/8973912.html 配置tomcat:https://blog.csdn.net/qq_33257 ...

  9. Python高阶函数和匿名函数

    高阶函数:就是把函数当成参数传递的一种函数:例如 注解: 1.调用add函数,分别执行abs(-8)和abs(11),分别计算出他们的值 2.最后在做和运算 map()函数 python内置的一个高阶 ...

  10. ELK+Filebeat+Kafka+ZooKeeper 构建海量日志分析平台(elk5.2+filebeat2.11)

    ELK+Filebeat+Kafka+ZooKeeper 构建海量日志分析平台 参考:http://www.tuicool.com/articles/R77fieA 我在做ELK日志平台开始之初选择为 ...