在进行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. WeX5学习笔记 - 01

    了解WeX5,有朋友突然自己开始学习WeX5,我了解后觉得挺不错的实用范围广,现在手机上的主流软件基本都可以采用WeX5进行开发,如淘宝,美团.手机银行等,所以自己也开始学习WeX5,WeX5是Ecl ...

  2. 将一个float型转化为内存存储格式的步骤

    将一个float型转化为内存存储格式的步骤为: (1)先将这个实数的绝对值化为二进制格式. (2)将这个二进制格式实数的小数点左移或右移n位,直到小数点移动到第一个有效数字的右边. (3)从小数点右边 ...

  3. nginx 配置 同一域名端口下,根据URL 导向不同的项目目录

    我们现在拥有2个项目.但是只有一个域名,通过nginx配置来实现以下url导向不同的项目. 后台管理台:{域名}/admin 用户客户端:{域名}/client server { listen 888 ...

  4. loadrunner11浏览器兼容性的问题

    最近项目中遇到了新开发的系统,全是HTML5和一些最新的前端框架技术,由于没有做浏览器兼容处理,所以该系统无法在IE浏览器进行操作,对firefox和google浏览器支持较好.但是又一个问题出现了, ...

  5. 显示react配置

    1. 由于react默认隐藏webpack配置需要手动显示. npm run eject //Are you sure you want to eject? This action is perman ...

  6. silverlight 基本信息学习随笔

    Silverlight还处于测试版本阶段 微软 silverlight 是一个跨浏览器.跨平台的插件.为网络带来下一代基于.NETFramework的媒体体验和丰富的交互式应用程序 他是一种新的web ...

  7. React事件绑定与解绑

    React中事件分类 React中事件绑定分为两种: 1.直接添加在React元素上的事件,这是React在基于Virtual DOM的基础上实现的符合w3c规范的合成事件(SyntheticEven ...

  8. 如何使用idea给系统平台添加子应用和应用的模块

    1.添加模块smartcity-portal,由于模块是在smartcity-framework工程下的,所以按照图片所示添加 2.smartcity-portal模块添加完成后,由于portal-d ...

  9. 总结React写参数的几种方式

    1.在render方法内 class Text extends Component{ render(){ const data=[1,2,3]; return( { data.map((item,in ...

  10. 关于atom无限意外退出的一个原因

    atom很好用,也有开发直接使用这个工具进行编码,我经常使用,最近突然会报意外退出的错误. 再重启应用依然会报这个错,然后重启电脑后可以正常使用. 非常疑惑. 原来,是因为Shadowsocks开启的 ...