在进行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. vue数据修改 但未渲染页面

    1. 普通的 `1.1 this.$set('obj',key,value); 1.2 this.splice(); 2.数据层次太多,没有触发render函数进行自动更新,需手动调用: this.$ ...

  2. jmeter的学习路线

  3. 2018-2019-2 学号20175223 实验二《Java面向对象程序设计》实验报告

    目录 北京电子科技学院(BESTI)实验报告 实验名称:实验二 面向对象程序设计 实验内容.步骤与体会: 一.实验二 面向对象程序设计-1 二.实验二 面向对象程序设计-2 三.实验二 面向对象程序设 ...

  4. MySQL5.7关于密码二三事

    MySQL5.7关于密码二三事 第一个:update user set password=password('root') where user='root' and host='localhost' ...

  5. 用 Cobertura 测量测试覆盖率

      尽管测试先行编程(test-first programming)和单元测试已不能算是新概念,但测试驱动的开发仍然是过去 10 年中最重要的编程创新.最好的一些编程人员在过去半个世纪中一直在使用这些 ...

  6. 【sklearn入门】通过sklearn实现k-means并可视化聚类结果

    import numpy as np from sklearn.cluster import KMeans from mpl_toolkits.mplot3d import Axes3D import ...

  7. entrySet用法 以及遍历map的用法

    entrySet用法 以及遍历map的用法   keySet是键的集合,Set里面的类型即key的类型entrySet是 键-值 对的集合,Set里面的类型是Map.Entry   1.keySet( ...

  8. 微信公众号服务器配置url二次修改

    最近微信公众号配置的服务器的域名和云服务到期,就想着更换到别的域名下的服务器:修改的时候出现token验证失败: 我同样的微信签名验证代码在以前服务器上是没问题的,但是修改到新的域名地址时候,总是提醒 ...

  9. linux ps 按进程消耗内存资源大小排序

    linux ps 关于sort的解释 --sort spec specify sorting order. Sorting syntax is [+|-]key[,[+|-]key[,...]] Ch ...

  10. ReentrantLock+线程池+同步+线程锁

    1.并发编程三要素? 1)原子性 原子性指的是一个或者多个操作,要么全部执行并且在执行的过程中不被其他操作打断,要么就全部都不执行. 2)可见性 可见性指多个线程操作一个共享变量时,其中一个线程对变量 ...