在进行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. Spring源码学习(6)——容器的功能扩展

    之前的随笔中借BeanFactory介绍了bean的解析和加载的完整过程,实际上,除了BeanFactory,spring还提供了一种功能更加强大的容器:ApplicationContext Appl ...

  2. https加密流程

     引用其它博主博客,在这里谢谢这位博主,原博客地址:https://blog.csdn.net/xincai/article/details/51954468 1,下面,用一幅图展示一下https建立 ...

  3. 闪付卡(QuickPass)隐私泄露原理

    0×00 前言 说到闪付卡,首先要从EMV开始,EMV是由Europay,MasterCard和VISA制定的基于IC卡的支付标准规范.目前基于EMV卡的非接触式支付的实现有三个:VISA的payWa ...

  4. python笔记1——关于文件的打开与读写

    一.文件的打开与关闭1.open,close函数 #-*- coding:utf-8 -*- # 1.w 写模式,它是不能读的,如果用w模式打开一个已经存在的文件,会清空以前的文件内容,重新写 # w ...

  5. SHELL输出带颜色字体

    输出特效格式控制:\033[0m  关闭所有属性  \033[1m   设置高亮度  \03[4m   下划线  \033[5m   闪烁  \033[7m   反显  \033[8m   消隐  \ ...

  6. Java编程思想 - 第11章 持有对象

    · 大量笔记存放在Github Java文件中,请移步查看:https://github.com/iGuure/AndroidCodeHub/tree/master/Java%20pratice/Th ...

  7. 运维shell全部语法进阶

    Linux运维之shell脚本进阶篇 一.if语句的使用 1)语法规则 1 2 3 4 5 6 7 8 9 if [条件]     then         指令 fi 或 if [条件];then ...

  8. (原创)Spice 网表范例

    一.常规网表 Inverter .lib "D:\lib\l0040ll_v1p4_1r.lib" TT .param SUPPLY=.1V .param T=10ns .para ...

  9. centos6.5卸载及安装git

    一.卸载原有的git 用whereis git命令来检查是否已经安装了git版本的 再使用命令:yum remove git卸载git 二.安装git (一)官网下载:https://mirrors. ...

  10. python面试题收集

    1.请问如何修改以下Python代码,使得下面的代码调用类A的show方法? class A(object) def show(self): print 'derived show' class B( ...