表单中的未处理异常在EXE中加载但在IDE中没有 [英] Unhandled Exception in Form Load in EXE but not in IDE

查看:41
本文介绍了表单中的未处理异常在EXE中加载但在IDE中没有的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的错误陷阱问题。在运行IDE时一切正常工作

罚款,但在EXE中运行时没有得到未处理的异常错误

消息框intead在我的Try .... Catch中块。


要看到这个,请创建一个包含两个表单的简单应用程序。表格1应该有一个按钮

。代码如下。在IDE中运行它并观察错误

,然后将该行为与运行构建的EXE时发生的情况进行比较。


有没有人看过这个?


谢谢,


马克


============ ===================================

公共类Form1


Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As

System.EventArgs)处理Button1.Click


Dim f As New Form2

试试


f.Show()


Catch ex As例外


MessageBox.Show(ex.Message)

f.Dispose()


结束尝试

结束子

结束类

公共类Form2


私有子Form2_Load(ByVal发送者为系统。 Object,ByVal e As

System.EventArgs)处理MyBase.Load


抛出新的ApplicationException(在form2 load中引发错误)


End Sub


结束班

I have a weird error trapping problem. When running the IDE everything works
fine but not when running in an EXE I get the Unhandled Exception Error
message box intead of the one in my Try....Catch Block.

To see this create a simple application with two forms. Form 1 should have
one button. The code is follows. Run this in the IDE and observe the error
and then compare that behavior to what happens when you run the built EXE.

Has anyone seen this?

Thanks,

Mark

===============================================

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim f As New Form2
Try

f.Show()

Catch ex As Exception

MessageBox.Show(ex.Message)
f.Dispose()

End Try
End Sub
End Class
Public Class Form2

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Throw New ApplicationException("error thrown in form2 load")

End Sub

End Class

推荐答案

嗨Mark,


首先,解决这个问题的方法是以下选项之一:

1)创建应用程序配置文件app.config为您的项目和编辑:


< configuration>

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

< / configuration>

您需要将主应用程序的< yourapp> .exe.config文件发布到

您的用户。


2)如果您安装自己的异常处理程序的目的是显示

异常,那么您不会不得不。默认情况下,WinForm有一个内置的全局

异常处理程序,它将捕获异常并显示默认的

异常对话框。您还可以自定义此对话框:
http:/ /samples.gotdotnet.com/quickst...FormsAppErrorH

andler.aspx


要了解此问题的背景,请继续阅读。


======


显示内置异常对话框,因为消息泵异常

处理程序正在工作。


如果你使用Reflector来查看

System.Windows.Forms.NativeWindow的反汇编代码,你会看到两个私有方法

" Callback"和DebuggableCallback。在回调中,我们在异常处理程序中包含消息

pump,以便得到消息泵的未处理异常

实际上不会消息消息泵导致

应用程序崩溃。


当在调试器中运行应用程序时,我们不会在
$ b $中捕获异常b NativeWindow.DebuggableCallback因为我们通常希望JIT调试器

来停止应用。


我们相信我们现在的行为代表了最好的轻松

的使用加上灵活性 - 如果你什么也不做你的应用程序就不会崩溃

如果你不处理异常,你可以自定义获得的对话框

显示你可以完全关闭这个行为。


======


希望这个帮助。如果有任何不清楚的地方,请随时发布。


此致,

Walter Wang(wa****@online.microsoft.com,删除' '在线'。')

微软在线社区支持


==================== ==============================

通过电子邮件收到我的帖子通知?请参阅
http://msdn.microsoft .com / subscripti ... ult.aspx#notif

ications。


注意:MSDN托管新闻组支持服务是针对非紧急问题

如果社区或微软支持人员在1个工作日内做出初步回复是可以接受的。请注意,每个跟随

的响应可能需要大约2个工作日作为支持

专业人士与您合作可能需要进一步调查才能达到

最有效的分辨率。该产品不适用于需要紧急,实时或基于电话的交互或复杂的b $ b项目分析和转储分析问题的情况。这种性质的问题最好通过联系

Microsoft客户支持服务(CSS)处理
href =http://msdn.microsoft.com/subscriptions/support/default.aspx\"target =_ blank> http://msdn.microsoft.com/subscripti...t/default.aspx

======================================== ==========


此帖子按原样提供。没有保证,也没有授予任何权利。

Hi Mark,

First, the fix to this issue is one of following options:
1) Create an application config file "app.config" for your project and edit:

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

You need to release this <yourapp>.exe.config file with your main app to
your user.

2) If your purpose of installing your own exception handler is to show the
exception, you don''t have to. By default, WinForm has a built-in global
exception handler which will catch the exception and show the default
exception dialog. You can also customize this dialog:
http://samples.gotdotnet.com/quickst...FormsAppErrorH
andler.aspx

To understand the background of this issue, read along.

======

The built-in exception dialog is shown because the message pump exception
handler is working.

If you use Reflector to see the disassembled code of
System.Windows.Forms.NativeWindow, you will see two private methods
"Callback" and "DebuggableCallback". In "Callback", we wrap the message
pump in an exception handler so that unhandled exception that gets as far
as the message pump does not actually unwind the message pump causing the
app to crash.

When an application is run in the debugger, we don''t catch exceptions in
NativeWindow.DebuggableCallback because we typically want the JIT debugger
to stop the app.

We believe that the behavior we have now represents the best possible ease
of use combined with flexibility -- if you do nothing your app won''t crash
if you don''t handle an exception, you can customize the dialog that gets
shown and you can turn off the behavior completely.

======

Hope this helps. Please feel free to post here if anything is unclear.

Sincerely,
Walter Wang (wa****@online.microsoft.com, remove ''online.'')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.


谢谢。


App.config更改修复此问题。这对我来说似乎更像一个bug而不是

功能< g> ....这是我用旧的VB6帽子.....我找到了一个

MSKB文章提到了这个,但它是
http:// support.microsoft.com/?kbid=836674


表示2005的表现不同。也许那篇文章应该是

更正,以表明问题出在2003年和2005年。


顺便说一下,添加这个JIT线是否有任何缺点在安全性或性能方面的配置



再次感谢,


Mark

Walter Wang [MSFT]" < wa **** @ online.microsoft.com写信息

news:ra ************** @ TK2MSFTNGXA01.phx.gbl ...
Thanks.

The App.config change fixed this. It would seem to be more of a bug than a
feature to me<g>.... that was with my old VB6 hat on..... I had found an
MSKB article that mentioned this but it
http://support.microsoft.com/?kbid=836674

Indicates that 2005 behaved differently. Perhaps that article should be
corrected to indicate the issue is with both 2003 and 2005.

By the way, is there any disadvantages of adding this JIT line to the config
in terms of security or performance?

Thanks again,

Mark
"Walter Wang [MSFT]" <wa****@online.microsoft.comwrote in message
news:ra**************@TK2MSFTNGXA01.phx.gbl...

嗨Mark,


首先,此问题的解决方案是以下选项之一:

1)创建应用程序配置文件app.config。为您的项目和

编辑:


< configuration>

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

< / configuration>

您需要将主应用程序的< yourapp> .exe.config文件发布到

您的用户。


2)如果您安装自己的异常处理程序的目的是显示

异常,那么您不会不得不。默认情况下,WinForm有一个内置的全局

异常处理程序,它将捕获异常并显示默认的

异常对话框。您还可以自定义此对话框:
http:/ /samples.gotdotnet.com/quickst...FormsAppErrorH

andler.aspx


要了解此问题的背景,请继续阅读。


======


显示内置异常对话框,因为消息泵异常

处理程序正在工作。


如果你使用Reflector来查看

System.Windows.Forms.NativeWindow的反汇编代码,你会看到两个私有方法

" Callback"和DebuggableCallback。在回调中,我们在异常处理程序中包含消息

pump,以便得到消息泵的未处理异常

实际上不会消息消息泵导致

应用程序崩溃。


当在调试器中运行应用程序时,我们不会在
$ b $中捕获异常b NativeWindow.DebuggableCallback因为我们通常希望JIT调试器

来停止应用。


我们相信我们现在的行为代表了最好的轻松

的使用加上灵活性 - 如果你什么也不做你的应用程序就不会崩溃

如果你不处理异常,你可以自定义获得的对话框

显示你可以完全关闭这个行为。


======


希望这个帮助。如果有任何不清楚的地方,请随时发布。


此致,

Walter Wang(wa****@online.microsoft.com,删除' '在线'。')

微软在线社区支持


==================== ==============================

通过电子邮件收到我的帖子通知?请参阅
http://msdn.microsoft .com / subscripti ... ult.aspx#notif

ications。


注意:MSDN托管新闻组支持服务是针对非紧急问题

如果社区或微软支持人员在1个工作日内做出初步回复是可以接受的。请注意,每个跟随

的响应可能需要大约2个工作日作为支持

专业人士与您合作可能需要进一步调查才能达到

最有效的分辨率。该产品不适用于需要紧急,实时或基于电话的交互或复杂的b $ b项目分析和转储分析问题的情况。这种性质的问题最好通过联系

Microsoft客户支持服务(CSS)处理
href =http://msdn.microsoft.com/subscriptions/support/default.aspx\"target =_ blank> http://msdn.microsoft.com/subscripti...t/default.aspx

======================================== ==========


此帖子按原样提供。没有保证,并且不授予

权利。
Hi Mark,

First, the fix to this issue is one of following options:
1) Create an application config file "app.config" for your project and
edit:

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

You need to release this <yourapp>.exe.config file with your main app to
your user.

2) If your purpose of installing your own exception handler is to show the
exception, you don''t have to. By default, WinForm has a built-in global
exception handler which will catch the exception and show the default
exception dialog. You can also customize this dialog:
http://samples.gotdotnet.com/quickst...FormsAppErrorH
andler.aspx

To understand the background of this issue, read along.

======

The built-in exception dialog is shown because the message pump exception
handler is working.

If you use Reflector to see the disassembled code of
System.Windows.Forms.NativeWindow, you will see two private methods
"Callback" and "DebuggableCallback". In "Callback", we wrap the message
pump in an exception handler so that unhandled exception that gets as far
as the message pump does not actually unwind the message pump causing the
app to crash.

When an application is run in the debugger, we don''t catch exceptions in
NativeWindow.DebuggableCallback because we typically want the JIT debugger
to stop the app.

We believe that the behavior we have now represents the best possible ease
of use combined with flexibility -- if you do nothing your app won''t crash
if you don''t handle an exception, you can customize the dialog that gets
shown and you can turn off the behavior completely.

======

Hope this helps. Please feel free to post here if anything is unclear.

Sincerely,
Walter Wang (wa****@online.microsoft.com, remove ''online.'')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.



实际上它没有解决问题。我的测试错误。使用下面提到的小的
程序,我添加了一个包含以下内容的app.config:


<?xml version =" 1.0"编码= QUOT; UTF-8英寸?>

< configuration>

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

< / configuration>

无论是否使用此行,应用程序的行为方式都相同。我有

附上来源,如果有任何帮助。


还有其他任何想法吗?


谢谢,


Mark


" Mark Lewis" < md ***** @ newsgroups.nospamwrote in message

news:Oq ************** @ TK2MSFTNGP04.phx.gbl ...
Actually it did not fix the problem. My error in testing. Using the small
program mentioned below I added an app.config with these contents:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>

The application behaves the same way with or without this line. I have
attached the source if that is of any help.

Any other ideas?

Thanks,

Mark

"Mark Lewis" <md*****@newsgroups.nospamwrote in message
news:Oq**************@TK2MSFTNGP04.phx.gbl...

谢谢。


App.config更改修复此问题。这对我来说似乎更像一个bug而不是

功能< g> ....这是我用旧的VB6帽子.....我找到了一个

MSKB文章提到了这个,但它是
http:// support.microsoft.com/?kbid=836674


表示2005的表现不同。也许那篇文章应该是

更正,以表明问题出在2003年和2005年。


顺便说一下,添加这个JIT线是否有任何缺点

配置

的安全性或性能?


再次感谢,


Mark


Walter Wang [MSFT]" < wa **** @ online.microsoft.com写信息

news:ra ************** @ TK2MSFTNGXA01.phx.gbl ...
Thanks.

The App.config change fixed this. It would seem to be more of a bug than a
feature to me<g>.... that was with my old VB6 hat on..... I had found an
MSKB article that mentioned this but it
http://support.microsoft.com/?kbid=836674

Indicates that 2005 behaved differently. Perhaps that article should be
corrected to indicate the issue is with both 2003 and 2005.

By the way, is there any disadvantages of adding this JIT line to the
config
in terms of security or performance?

Thanks again,

Mark
"Walter Wang [MSFT]" <wa****@online.microsoft.comwrote in message
news:ra**************@TK2MSFTNGXA01.phx.gbl...

>嗨Mark,

首先,此问题的解决方案是以下选项之一:
1)创建应用程序配置文件app.config为您的项目和
编辑:

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

您需要使用主应用程序发布此< yourapp> .exe.config文件

您的用户。

2)如果您安装自己的异常处理程序的目的是为了显示
异常,那么您不必这样做。默认情况下,WinForm有一个内置的全局异常处理程序,它将捕获异常并显示默认的异常对话框。您还可以自定义此对话框:
http:/ /samples.gotdotnet.com/quickst...FormsAppErrorH
andler.aspx

要了解这个问题的背景,请继续阅读。

======

显示内置异常对话框,因为消息泵异常
处理程序正常工作。

如果使用Reflector查看反汇编代码System.Windows.Forms.NativeWindow,你会看到两个私有方法
Callback和DebuggableCallback。在回调中,我们将消息
泵包装在一个异常处理程序中,这样得到的消息泵的未处理异常实际上并没有解开消息泵导致
应用程序崩溃。

当一个应用程序在调试器中运行时,我们在NativeWindow.DebuggableCallback中没有捕获异常,因为我们通常需要JIT
调试器
停止应用程序。

我们相信,我们现在的行为代表了最好的使用和易用性以及灵活性 - 如果你什么都不做你的应用程序不会
崩溃
如果您没有处理异常,您可以自定义显示的对话框,您可以完全关闭该行为。

== ====

希望这会有所帮助。如果有任何不清楚的地方,请随时在这里发帖。

真诚的,
Walter Wang(wa****@online.microsoft.com,删除''在线。'')
Microsoft在线社区支持

==================================== ============= =
通过电子邮件收到我的帖子通知?请参阅
http://msdn.microsoft .com / subscripti ... ult.aspx#notif
ications。

注意:MSDN管理新闻组支持服务是针对非紧急问题的。
/>如果社区或Microsoft支持工程师在1个工作日内做出初步响应,则可以接受。请注意,每个
后续响应可能需要大约2个工作日,因为与您合作的专业人员可能需要进一步调查才能达到最有效的解决方案。此产品不适用于需要紧急,实时或基于电话的交互或复杂的项目分析和转储分析问题的情况。这种性质的问题最好通过与Microsoft客户支持服务(CSS)联系来与专门的Microsoft支持工程师一起处理
http://msdn.microsoft.com/subscripti...t/default.aspx
== =============================================== =

此帖子是原样提供的。没有保证,也没有授予
权利。
>Hi Mark,

First, the fix to this issue is one of following options:
1) Create an application config file "app.config" for your project and
edit:

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

You need to release this <yourapp>.exe.config file with your main app
to
your user.

2) If your purpose of installing your own exception handler is to show
the
exception, you don''t have to. By default, WinForm has a built-in global
exception handler which will catch the exception and show the default
exception dialog. You can also customize this dialog:
http://samples.gotdotnet.com/quickst...FormsAppErrorH
andler.aspx

To understand the background of this issue, read along.

======

The built-in exception dialog is shown because the message pump exception
handler is working.

If you use Reflector to see the disassembled code of
System.Windows.Forms.NativeWindow, you will see two private methods
"Callback" and "DebuggableCallback". In "Callback", we wrap the message
pump in an exception handler so that unhandled exception that gets as far
as the message pump does not actually unwind the message pump causing the
app to crash.

When an application is run in the debugger, we don''t catch exceptions in
NativeWindow.DebuggableCallback because we typically want the JIT
debugger
to stop the app.

We believe that the behavior we have now represents the best possible
ease
of use combined with flexibility -- if you do nothing your app won''t
crash
if you don''t handle an exception, you can customize the dialog that gets
shown and you can turn off the behavior completely.

======

Hope this helps. Please feel free to post here if anything is unclear.

Sincerely,
Walter Wang (wa****@online.microsoft.com, remove ''online.'')
Microsoft Online Community Support

================================================= =
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent
issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each
follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
================================================= =

This posting is provided "AS IS" with no warranties, and confers no
rights.




这篇关于表单中的未处理异常在EXE中加载但在IDE中没有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆