有个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!
...全文
879 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)

110,533

社区成员

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

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

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