有个Exception居然 Catch 不住,特高分请教高手

jsjwql 2007-01-10 07:11:38
问题是这样的,我在程序中要调用一个Activex控件,当该控件的运行环境被破坏掉时,在release析构该控件的对象时会抛出一个异常,我就加了try...catch语句,在按F5 调试代码的时候,可以看到这个异常被catch住了,但是如果直接运行可执行文件的时候,这个异常就不能被catch住,好像时被.net framework catch住的,然后提示
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
at System.Windows.Forms.Control.DefWndProc(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.AxHost.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
Autoloader
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///H:/lib/Debug/Autoloader.exe
----------------------------------------
Connectivity.Common
Assembly Version: 1.0.2564.32478
Win32 Version: 1.0.2564.32478
CodeBase: file:///H:/lib/Debug/Connectivity.Common.DLL
----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
.
.
.
.
.
.
.
.
.
.
.
.

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.

很奇怪,不知如何解决,特请教,thanks!
...全文
926 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
liujia_0421 2007-01-11
  • 打赏
  • 举报
回复
好长,先顶下,明天接着看..
jetxia 2007-01-11
  • 打赏
  • 举报
回复
stou 2007-01-11
  • 打赏
  • 举报
回复
是不是语法有错?
jsjwql 2007-01-11
  • 打赏
  • 举报
回复
我用的方法是
try
{
dispose 对象
}
catch(Exception ex)
{
弹出一个对话框
}

你说的WndProc是什么方法?
Mittermeyer 2007-01-11
  • 打赏
  • 举报
回复
你在什么地方加的Catch?
如果是上面地例子的话,最简单的做法就是冲在WndProc方法,只在其中加个try...catch应该就行了。
scow 2007-01-11
  • 打赏
  • 举报
回复
如果无法预计所有可能出现的Exception类型,那就应该让程序去自动终止它。
catch的原则是不能catch不特定的Exception,如Exception类型,而应该是IOException这样有特定类型的。处于安全考虑,由于不知这种不特定的Exception会导致程序处于何种状态,catch它是有问题的。
jsjwql 2007-01-11
  • 打赏
  • 举报
回复
sunyou(砂子),谢谢,还是不行,即使用
try
{....}
catch(Exception ex)
{...}
都catch不了
sunyou 2007-01-11
  • 打赏
  • 举报
回复
在试图读写受保护内存时引发的异常。
当非托管或不安全代码试图读写未分配或不具有访问权限的内存空间时,就会产生访问冲突。这种情况通常因为指针具有错误的值而发生。并非所有通过错误指针的读写操作都会引发访问冲突,所以访问冲突通常指示已经通过错误指针进行多次读写操作,并且内存内容可能已损坏。因此,访问冲突几乎总是指示存在严重的编程错误。在 .NET Framework 2.0 版中,AccessViolationException 清楚地标识了这些错误。

在完全由可验证托管代码组成的程序中,所有引用都有效或者为空,因而不会产生访问冲突。AccessViolationException 只在可验证托管代码与非托管代码或非安全托管代码交互时才会引发。


试试
try
{
...
}
catch(AccessViolationException ex)
{
....
}
wml413 2007-01-11
  • 打赏
  • 举报
回复
up
hertcloud 2007-01-11
  • 打赏
  • 举报
回复
activex 自身的错误
导致.net 运行时出错。
juqiang 2007-01-11
  • 打赏
  • 举报
回复
AV异常,你的ocx有问题
GXY2005 2007-01-11
  • 打赏
  • 举报
回复
mark
没遇到过。
兔子-顾问 2007-01-11
  • 打赏
  • 举报
回复
mark
没遇到过。
jsjwql 2007-01-11
  • 打赏
  • 举报
回复
谢谢,你的分析,有谁知道有什么简单的方面解决吗?
liujia_0421 2007-01-11
  • 打赏
  • 举报
回复
不好说,大致以下几个原因:

1.非托管代码或不安全代码试图对尚未分配的或不具有访问权限的内存进行读操作或写操作,就会发生访问冲突。

2.试图在可验证代码中引用空引用的任何操作都将引发 NullReferenceException,根据平台的不同,也可能表现为AccessViolationException
jonescheng 2007-01-11
  • 打赏
  • 举报
回复
试试这个
catch(COMException ex)
jsjwql 2007-01-11
  • 打赏
  • 举报
回复
不会是语法错误,语法错误就不会通过编译的,我现在就想能通过什么方法把just-in-time (JIT) debugging 用代码给关闭掉。
我在网上找到一点相关的内容
“If your application is running without debugging, you need to disable the
unhandled exception dialog box by performing the following step:

1. Start Registry Editor and locate the following Registry subkey in the
HKEY_LOCAL_MACHINE subtree:

\SOFTWARE\MICROSOFT\WINDOWS NT\CURRENTVERSION\AEDEBUG

Rename the Debugger value name. I belive the following MSDN article is also
helpful:

Specifying the Debugger for Unhandled User Mode Exceptions
http://support.microsoft.com/?id=121434

2. To disable the JIT debugger dialog box, you can change the following
registry key:

HKEY_LOCAL_MACHINE\Software\Microsoft\.NetFramework\DbgJITDebugLaunchSetting
to the value 1 will disable JIT debugging.

Please let me know the result.”


不知道有没有一点更好的方法
股神 2007-01-10
  • 打赏
  • 举报
回复
up
lextm 2007-01-10
  • 打赏
  • 举报
回复
注册UnhandledExceptionHandler,查查MSDN相关就好了。CodeProject.com上面还有别人给出的通用解决方法可以参考。
kissknife 2007-01-10
  • 打赏
  • 举报
回复
没遇过,只能up..
加载更多回复(1)
内容概要:本文针对无刷直流电机驱动的电子机械制动(EMB)执行器,建立了考虑Stribeck摩擦性的非线性耦合动力学模型,并在Simulink环境中完成了系统级仿真分析。研究综合集成了电机动力学、齿轮传动机构与制动执行机构的动力学性,构建了高保真的机电一体化系统模型。重点引入Stribeck摩擦模型以精确描述低速工况下执行器内部存在的静摩擦、粘滞摩擦与库仑摩擦之间的过渡行为,有效提升了系统在启停、反向运动等瞬态过程中的动态响应仿真精度。通过多工况仿真验证了模型的有效性,能够准确反映摩擦引起的爬行、滞后与定位误差等非线性现象,为EMB系统的高性能控制算法设计(如摩擦补偿、滑模控制)与结构优化提供了高可信度的仿真平台。; 适合人群:从事汽车电子制动系统、电机驱动控制、机电系统建模与仿真研究的研究生、科研人员及工程技术人员,需具备扎实的机械动力学、自动控制理论基础和MATLAB/Simulink仿真能力。; 使用场景及目标:①用于高精度电子机械制动系统的设计验证与性能预测;②为消除摩擦非线性影响的先进控制策略(如自适应控制、智能控制)提供精确的被控对象模型;③深入探究Stribeck摩擦等非线性因素对系统动态性能(如响应延迟、稳态误差)的作用机理; 阅读建议:读者应结合提供的Simulink模型文件,深入剖析Stribeck摩擦模块的数学实现与参数辨识方法,建议通过改变输入指令(如阶跃、正弦)和负载条件进行对比仿真,以直观理解非线性摩擦对系统动态性的影响。

111,129

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧