设计时和运行时之间的异常处理差异 [英] Exception Handling difference between Design-Time and Run-Time

查看:62
本文介绍了设计时和运行时之间的异常处理差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是例子:


Dim frm As New FORM1

尝试


frm。 show


Catch ex As Exception


msgbox ex.message


结束尝试


假设FORM1在load事件中抛出异常。在

设计时环境中运行此代码,异常将被代码捕获。运行它

运行时并且异常未处理。


有人说这是一个错误。你能(微软)确认这个吗?

我好吗?并确认它是否是设计或运行时的错误?那是什么

推荐的工作轮次是这样的。


谢谢,


Nick Charnock


----------------

这篇文章是对微软的建议,微软回复了

投票最多的建议。要投票支持此建议,请点击我

同意消息窗格中的按钮。如果您没有看到该按钮,请按照此

链接打开Microsoft基于Web的新闻阅读器中的建议,然后点击我同意按钮。在消息窗格中。

http://www.microsoft.com/communities...t.languages.vb

Here''s the example:

Dim frm As New FORM1
Try

frm.show

Catch ex As Exception

msgbox ex.message

End Try

Say FORM1 throws an exception in the load event. Run this in the
Design-Time enviroment and the exception is caught by the code. Run it in
Run-Time and the exception is unhandled.

Some people have said this is a bug. Can you (Microsoft) confirm this for
me please? And confirm whether its a bug in design or run-time? And what
the recomended work round for this is.

Thanks,

Nick Charnock

----------------
This post is a suggestion for Microsoft, and Microsoft responds to the
suggestions with the most votes. To vote for this suggestion, click the "I
Agree" button in the message pane. If you do not see the button, follow this
link to open the suggestion in the Microsoft Web-based Newsreader and then
click "I Agree" in the message pane.

http://www.microsoft.com/communities...t.languages.vb

推荐答案

Nick,

|假设FORM1在load事件中抛出异常。在

|中运行此命令设计时环境和代码捕获异常。在

|中运行它运行时和异常未处理。

设计时环境默认为如果未处理异常 -

进入调试器在Debug - Exceptions - Common Language Runtime

Exception下。


在运行时,您没有处理异常的异常处理程序

WIndows Forms活动。


你的try / catch块只处理Form.Show本身抛出的事件。


处理Form.Load事件中的异常需要使用Global

异常处理程序。


根据您创建的应用程序类型,.NET有三个

不同的全局异常处理程序。


对于ASP.NET,请查看:

System.Web.HttpApplication.Error事件

通常放在你的Global.asax文件中。


对于控制台应用程序,请查看:

System.AppDomain.UnhandledException事件

在Sub Main中使用AddHandler。


对于Windows Forms,请查看:

System.Windows.Forms.Application.ThreadException事件

在Sub Mai中使用AddHandler n。


在您的应用程序中组合上述全局处理程序是有益的,因为

以及将您的Sub Main包装在try catch本身中。


2004年6月的MSDN杂志中有一篇文章展示了如何在.NET中实现全局异常处理,解释了为什么&当你

使用上述处理程序中的多个......

http://msdn.microsoft.com/msdnmag/is...T/default.aspx


例如:在我的Windows窗体应用程序中,我将有一个处理程序附加到

Application.ThreadException事件,以及我的Main中的Try / Catch。

在Main中的Try / Catch仅捕获异常,如果MainForm的构造函数
引发异常,Application.ThreadException处理程序将捕获所有

来自任何表单/控件事件处理程序的未被捕获的异常。


Public Shared Sub Main()

AddHandler Application.ThreadException,AddressOf

Application_ThreadException

Application.EnableVisualStyles()

Application.DoEvents()

尝试

Application.Run(新增功能MainForm)

Catch ex As Exception

''log ex for later diagnosis

''可选择显示漂亮版本给用户

结束尝试

结束子


私有共享子Application_ThreadException(ByVal发件人为对象,

ByVal e As System.Threading.ThreadExceptionEventArgs)


''记录e.Exception以便以后诊断。

''可选地显示漂亮 ;版本给用户


结束子


希望这有帮助

Jay


chopsnsauce < CH ********* @ discussions.microsoft.com>在留言中写道

新闻:BF ********************************** @ microsof t.com ...

|这是一个例子:

|

| Dim frm As New FORM1

|试试

|

| frm.show

|

| C ex ex As Exception

|

| msgbox ex.message

|

|结束尝试

|

|假设FORM1在load事件中抛出异常。在

|中运行此命令设计时环境和代码捕获异常。在

|中运行它运行时和异常未处理。

|

|有人说这是一个bug。你可以(微软)确认这个

|我好吗?并确认它是否是设计或运行时的错误?什么

|推荐的工作轮为。

|

|谢谢,

|

| Nick Charnock

|

|

|

| ----------------

|这篇文章是微软的建议,微软回复了

|投票最多的建议。要投票支持此建议,请点击我

|同意]消息窗格中的按钮。如果你没有看到按钮,请按照

这个

|链接打开微软基于Web的新闻阅读器中的建议,然后

|点击我同意在消息窗格中。

|

|
http://www.microsoft.com /communities...t.languages.vb
Nick,
| Say FORM1 throws an exception in the load event. Run this in the
| Design-Time enviroment and the exception is caught by the code. Run it in
| Run-Time and the exception is unhandled.
The Design-Time enviroment defaults to "If the exception is not handled -
break into the debugger" under "Debug - Exceptions - Common Language Runtime
Exception".

At runtime you do not have an exception handler that handles exceptions in
WIndows Forms Events.

Your try/catch block is only handling events that Form.Show itself throws.

To handle exceptions in the Form.Load event you need to use a Global
Exception Handler.

Depending on the type of application you are creating, .NET has three
different global exception handlers.

For ASP.NET look at:
System.Web.HttpApplication.Error event
Normally placed in your Global.asax file.

For console applications look at:
System.AppDomain.UnhandledException event
Use AddHandler in your Sub Main.

For Windows Forms look at:
System.Windows.Forms.Application.ThreadException event
Use AddHandler in your Sub Main.

It can be beneficial to combine the above global handlers in your app, as
well as wrap your Sub Main in a try catch itself.

There is an article in the June 2004 MSDN Magazine that shows how to
implement the global exception handling in .NET that explains why & when you
use multiple of the above handlers...

http://msdn.microsoft.com/msdnmag/is...T/default.aspx

For example: In my Windows Forms apps I would have a handler attached to the
Application.ThreadException event, plus a Try/Catch in my Main. The
Try/Catch in Main only catches exceptions if the constructor of the MainForm
raises an exception, the Application.ThreadException handler will catch all
uncaught exceptions from any form/control event handlers.

Public Shared Sub Main()
AddHandler Application.ThreadException, AddressOf
Application_ThreadException
Application.EnableVisualStyles()
Application.DoEvents()
Try
Application.Run(New MainForm)
Catch ex As Exception
'' log ex for later diagnosis
'' optionally show "pretty" version to user
End Try
End Sub

Private Shared Sub Application_ThreadException(ByVal sender As Object,
ByVal e As System.Threading.ThreadExceptionEventArgs)

'' Log the e.Exception for later diagnosis.
'' optionally show "pretty" version to user

End Sub

Hope this helps
Jay

"chopsnsauce" <ch*********@discussions.microsoft.com> wrote in message
news:BF**********************************@microsof t.com...
| Here''s the example:
|
| Dim frm As New FORM1
| Try
|
| frm.show
|
| Catch ex As Exception
|
| msgbox ex.message
|
| End Try
|
| Say FORM1 throws an exception in the load event. Run this in the
| Design-Time enviroment and the exception is caught by the code. Run it in
| Run-Time and the exception is unhandled.
|
| Some people have said this is a bug. Can you (Microsoft) confirm this for
| me please? And confirm whether its a bug in design or run-time? And what
| the recomended work round for this is.
|
| Thanks,
|
| Nick Charnock
|
|
|
| ----------------
| This post is a suggestion for Microsoft, and Microsoft responds to the
| suggestions with the most votes. To vote for this suggestion, click the "I
| Agree" button in the message pane. If you do not see the button, follow
this
| link to open the suggestion in the Microsoft Web-based Newsreader and then
| click "I Agree" in the message pane.
|
|
http://www.microsoft.com/communities...t.languages.vb


感谢Jay的回复。


更多问题。


是否有可能使设计和运行时环境在

中表现相同?

这是我的第一个VB.NET项目(从VB6.0开始)和这个问题已经

真的把我抓了出来。


在应用程序级别捕获异常也行但理想情况下我想要在frm.Show级别捕获异常。

你是说这在.NET中是不可能的吗?


谢谢,


尼克

Jay B. Harlow [MVP - Outlook]"写道:
Thanks for the response Jay.

More questions.

Is it possible to make the Design and Run-Time enviroments behave in the
same way?
This is my first VB.NET project (moving from VB6.0) and this problem has
REALLY caught me out.

Also catching the exception at the application level is OK but ideally I
want to catch the exception at the frm.Show level.
Are you saying that this is not possible in .NET???

Thanks,

Nick
"Jay B. Harlow [MVP - Outlook]" wrote:
尼克,
|假设FORM1在load事件中抛出异常。在
|中运行设计时环境和代码捕获异常。在
|中运行它运行时和异常未处理。
设计时环境默认为如果未处理异常 -
进入调试器在Debug - Exceptions - Common Language Runtime
Exception下。

在运行时,您没有处理
WIndows Forms事件中异常的异常处理程序。

你的try / catch块只处理Form.Show本身抛出的事件。

要处理Form.Load事件中的异常,你需要使用Global
异常处理程序。

根据您正在创建的应用程序类型,.NET有三个不同的全局异常处理程序。

对于ASP.NET,请查看:
System.Web.HttpApplication.Error事件
通常放在你的Global.asax文件中。

对于控制台应用程序,请看:
System.AppDomain.UnhandledException事件
使用Sub Main中的AddHandler。

对于Windows窗体,请查看:
System.Windows.Forms.Application.ThreadException事件
在Sub Main中使用AddHandler。
<结合上述全球手可能是有益的你的应用程序中的lers,以及将你的Sub Main包装成try catch本身。

2004年6月的MSDN杂志中有一篇文章展示了如何实现.NET中的全局异常处理解释了为什么&当你使用上述多个处理程序时......

http://msdn.microsoft.com/msdnmag/is...T/default.aspx

例如:In我的Windows窗体应用程序我将有一个处理程序附加到
Application.ThreadException事件,以及我的Main中的Try / Catch。如果MainForm的构造函数引发异常,则Main中的Try / Catch仅捕获异常,Application.ThreadException处理程序将捕获来自任何表单/控件事件处理程序的所有未捕获的异常。 br />
Public Shared Sub Main()
AddHandler Application.ThreadException,AddressOf
Application_ThreadException
Application.EnableVisualStyles()
Application.DoEvents()
尝试
Application.Run(New MainForm)
Catch ex As Exception
''log ex for later diagnosis
''可选地显示漂亮版本给用户
结束尝试
结束子

私有共享子Application_ThreadException(ByVal发送者为对象,
ByVal e As System.Threading.ThreadExceptionEventArgs)

''记录e.Exception以便以后诊断。
''可选地显示漂亮。版本给用户

End Sub

希望这有帮助
Jay

" chopsnsauce" < CH ********* @ discussions.microsoft.com>在消息中写道
新闻:BF ********************************** @ microsof t.com。 ..
|这是一个例子:
|
| Dim frm As New FORM1
|试试
|
| frm.show
|
|赶上例外情况
|
| msgbox ex.message
|
|结束尝试
|
|假设FORM1在load事件中抛出异常。在
|中运行设计时环境和代码捕获异常。在
|中运行它运行时和异常未处理。
|
|有人说这是一个bug。你能否(微软)确认这个为
|我好吗?并确认它是否是设计或运行时的错误?什么
|推荐的工作轮次是这样的。
|
|谢谢,
|
|尼克查诺克
|
|
|
| ----------------
|这篇文章是微软的建议,微软回应了
|投票最多的建议。要投票赞成此建议,请点击我
|同意]消息窗格中的按钮。如果您没有看到按钮,请按照
这个
|链接以打开Microsoft基于Web的新闻阅读器中的建议,然后
|点击我同意在消息窗格中。
|
|
http://www.microsoft.com/communities...t.languages .vb
Nick,
| Say FORM1 throws an exception in the load event. Run this in the
| Design-Time enviroment and the exception is caught by the code. Run it in
| Run-Time and the exception is unhandled.
The Design-Time enviroment defaults to "If the exception is not handled -
break into the debugger" under "Debug - Exceptions - Common Language Runtime
Exception".

At runtime you do not have an exception handler that handles exceptions in
WIndows Forms Events.

Your try/catch block is only handling events that Form.Show itself throws.

To handle exceptions in the Form.Load event you need to use a Global
Exception Handler.

Depending on the type of application you are creating, .NET has three
different global exception handlers.

For ASP.NET look at:
System.Web.HttpApplication.Error event
Normally placed in your Global.asax file.

For console applications look at:
System.AppDomain.UnhandledException event
Use AddHandler in your Sub Main.

For Windows Forms look at:
System.Windows.Forms.Application.ThreadException event
Use AddHandler in your Sub Main.

It can be beneficial to combine the above global handlers in your app, as
well as wrap your Sub Main in a try catch itself.

There is an article in the June 2004 MSDN Magazine that shows how to
implement the global exception handling in .NET that explains why & when you
use multiple of the above handlers...

http://msdn.microsoft.com/msdnmag/is...T/default.aspx

For example: In my Windows Forms apps I would have a handler attached to the
Application.ThreadException event, plus a Try/Catch in my Main. The
Try/Catch in Main only catches exceptions if the constructor of the MainForm
raises an exception, the Application.ThreadException handler will catch all
uncaught exceptions from any form/control event handlers.

Public Shared Sub Main()
AddHandler Application.ThreadException, AddressOf
Application_ThreadException
Application.EnableVisualStyles()
Application.DoEvents()
Try
Application.Run(New MainForm)
Catch ex As Exception
'' log ex for later diagnosis
'' optionally show "pretty" version to user
End Try
End Sub

Private Shared Sub Application_ThreadException(ByVal sender As Object,
ByVal e As System.Threading.ThreadExceptionEventArgs)

'' Log the e.Exception for later diagnosis.
'' optionally show "pretty" version to user

End Sub

Hope this helps
Jay

"chopsnsauce" <ch*********@discussions.microsoft.com> wrote in message
news:BF**********************************@microsof t.com...
| Here''s the example:
|
| Dim frm As New FORM1
| Try
|
| frm.show
|
| Catch ex As Exception
|
| msgbox ex.message
|
| End Try
|
| Say FORM1 throws an exception in the load event. Run this in the
| Design-Time enviroment and the exception is caught by the code. Run it in
| Run-Time and the exception is unhandled.
|
| Some people have said this is a bug. Can you (Microsoft) confirm this for
| me please? And confirm whether its a bug in design or run-time? And what
| the recomended work round for this is.
|
| Thanks,
|
| Nick Charnock
|
|
|
| ----------------
| This post is a suggestion for Microsoft, and Microsoft responds to the
| suggestions with the most votes. To vote for this suggestion, click the "I
| Agree" button in the message pane. If you do not see the button, follow
this
| link to open the suggestion in the Microsoft Web-based Newsreader and then
| click "I Agree" in the message pane.
|
|
http://www.microsoft.com/communities...t.languages.vb



Nick,

|是否有可能使设计和运行时环境在

|中表现出来同样的方式?

您是否尝试关闭我在IDE中提到的选项?


|在应用程序级别捕获异常也可以,但理想情况下我是
|想要在frm.Show级别捕获异常。

|你是说在.NET中这是不可能的吗?

是的我说它不可能,因为这不是.NET中的Windows窗体

作品。你可以尝试添加一个本地处理程序,Form.Show,删除本地的

处理程序,但是我不确定你会得到准确的处理程序。结果,因为另一个

事件(另一个Win32消息)可能会在您连接本地处理程序的时候抛出异常。表单存在的时间比Form.Show方法的生命周期长得多。


我理解为响应WM_CREATE而引发Form.Load事件

Win32消息。


发送WM_CREATE消息是为了响应创建

底层Win32窗口的句柄。当框架将Win32消息转换为

控制/表单事件时,它会在Try / Catch中提升这些事件,这些事件会引发Application.ThreadException,因为通常会处理这些消息

通过消息泵,在.NET中使用消息泵。是Application.Run

方法。在Win32中,消息泵在是一个调用GetMessage的循环,

TranslateMessage和DispatchMessage Win32 API。


希望这有帮助

Jay

" chopsnsauce" < CH ********* @ discussions.microsoft.com>在留言中写道

新闻:0C ********************************** @ microsof t.com ...

|感谢Jay的回复。

|

|更多问题。

|

|是否有可能使设计和运行时环境在

|中表现出来同样的方式?

|这是我的第一个VB.NET项目(从VB6.0开始),这个问题有

|真的把我抓了出去。

|

|在应用程序级别捕获异常也可以,但理想情况下我是
|想要在frm.Show级别捕获异常。

|你是说这在.NET中是不可能的吗?

|

|谢谢,

|

|尼克

|

|

| Jay B. Harlow [MVP - Outlook]"写道:

|

| >尼克,

| > |假设FORM1在load事件中抛出异常。在

|中运行此命令> |设计时环境和代码捕获异常。在

|中运行

吧> |运行时和异常未处理。

| >设计时环境默认为如果例外不是

处理 -

| >闯入调试器在调试 - 例外 - 通用语言

运行时

| >例外情况。

| >

| >在运行时,你没有一个异常处理程序来处理

|中的异常

> WIndows Forms Events。

| >

| >你的try / catch块只处理Form.Show本身的事件

抛出。

| >

| >要处理Form.Load事件中的异常,您需要使用Global

| >异常处理程序。

| >

| >根据您创建的应用程序类型,.NET有三个

| >不同的全局异常处理程序。

| >

| >对于ASP.NET,请查看:

| > System.Web.HttpApplication.Error事件

| >通常放在你的Global.asax文件中。

| >

| >对于控制台应用程序,请查看:

| > System.AppDomain.UnhandledException事件

| >在Sub Main中使用AddHandler。

| >

| >对于Windows Forms,请查看:

| > System.Windows.Forms.Application.ThreadException事件

| >在Sub Main中使用AddHandler。

| >

| >在您的应用程序中组合上述全局处理程序是有益的,

as

| >以及将您的Sub Main包装成try catch本身。

| >

| > 2004年6月的MSDN杂志中有一篇文章展示了如何获得
| >在.NET中实现全局异常处理,解释了为什么&当



| >使用多个上述处理程序...

| >

| > http://msdn.microsoft.com/ msdnmag /是... T / default.aspx

| >

| >例如:在我的Windows窗体应用程序中,我将附加一个处理程序



| > Application.ThreadException事件,以及我的Main中的Try / Catch。

| >如果

MainForm

|的构造函数,在Main中尝试/ Catch只捕获异常。 >引发异常,Application.ThreadException处理程序将捕获

all

| >来自任何表单/控件事件处理程序的未被捕获的异常。

| >

| > Public Shared Sub Main()

| > AddHandler Application.ThreadException,AddressOf

| > Application_ThreadException

| > Application.EnableVisualStyles()

| > Application.DoEvents()

| >试试

| > Application.Run(New MainForm)

| >赶上例外情况

| > ''登录以供日后诊断

| > ''可选地显示漂亮版本给用户

| >结束尝试

| >结束子

| >

| >私有共享子Application_ThreadException(ByVal发件人为

对象,

|> ByVal e As System.Threading.ThreadExceptionEventArgs)

| >

| > ''记录e.Exception以便以后诊断。

| > ''可选地显示漂亮版本给用户

| >

| >结束子

| >

| >希望这有助于

| >周杰伦

| >

| >

| >

| > " chopsnsauce" < CH ********* @ discussions.microsoft.com>在消息中写道

| >新闻:BF ********************************** @ microsof t.com ...

| > |这是一个例子:

| > |

| > | Dim frm As New FORM1

| > |试试

| > |

| > | frm.show

| > |

| > |赶上例外情况

| > |

| > | msgbox ex.message

| > |

| > |结束尝试

| > |

| > |假设FORM1在load事件中抛出异常。在

|中运行此命令> |设计时环境和代码捕获异常。在

|中运行

吧> |运行时和异常未处理。

| > |

| > |有人说这是一个bug。你能否(微软)确认这个



| > |我好吗?并确认它是否是设计或运行时的错误?并且

什么

| > |推荐的工作轮次是这样的。

| > |

| > |谢谢,

| > |

| > |尼克查诺克

| > |

| > |

| > |

| > | ----------------

| > |这篇文章是微软的建议,微软回复了

| > |投票最多的建议。要投票支持此建议,请点击

I

| > |同意]消息窗格中的按钮。如果你没有看到按钮,

请关注

| >这个

| > |链接打开微软基于Web的新闻阅读器中的建议和

然后

| > |点击我同意在消息窗格中。

| > |

| > |

| >
http://www.microsoft.com/communities...t.languages.vb

| >

| >

| >
Nick,
| Is it possible to make the Design and Run-Time enviroments behave in the
| same way?
Have you tried turning the option I mentioned in the IDE off?

| Also catching the exception at the application level is OK but ideally I
| want to catch the exception at the frm.Show level.
| Are you saying that this is not possible in .NET???
Yes I''m saying its not possible, as that is not how Windows Forms in .NET
works. You could try adding a local handler, Form.Show, Remove the local
handler, however I''m not sure you will get "accurate" results, as another
event (another Win32 message) could throw an exception during the time you
had the local handler attached. Also the form exists for much longer then
the lifetime of Form.Show method.

I understand that the Form.Load event is raised in response to WM_CREATE
Win32 message.

The WM_CREATE message is sent in response to creating the handle to the
underlying Win32 window. When the framework translates Win32 message to
Control/Form Events it wraps raising those events in a Try/Catch that raises
the Application.ThreadException, as normally those messages are processed
via the "message pump", in .NET the "message pump" is the Application.Run
method. In Win32 the "message pump" is a loop that calls the GetMessage,
TranslateMessage, and DispatchMessage Win32 APIs.

Hope this helps
Jay

"chopsnsauce" <ch*********@discussions.microsoft.com> wrote in message
news:0C**********************************@microsof t.com...
| Thanks for the response Jay.
|
| More questions.
|
| Is it possible to make the Design and Run-Time enviroments behave in the
| same way?
| This is my first VB.NET project (moving from VB6.0) and this problem has
| REALLY caught me out.
|
| Also catching the exception at the application level is OK but ideally I
| want to catch the exception at the frm.Show level.
| Are you saying that this is not possible in .NET???
|
| Thanks,
|
| Nick
|
|
| "Jay B. Harlow [MVP - Outlook]" wrote:
|
| > Nick,
| > | Say FORM1 throws an exception in the load event. Run this in the
| > | Design-Time enviroment and the exception is caught by the code. Run
it in
| > | Run-Time and the exception is unhandled.
| > The Design-Time enviroment defaults to "If the exception is not
handled -
| > break into the debugger" under "Debug - Exceptions - Common Language
Runtime
| > Exception".
| >
| > At runtime you do not have an exception handler that handles exceptions
in
| > WIndows Forms Events.
| >
| > Your try/catch block is only handling events that Form.Show itself
throws.
| >
| > To handle exceptions in the Form.Load event you need to use a Global
| > Exception Handler.
| >
| > Depending on the type of application you are creating, .NET has three
| > different global exception handlers.
| >
| > For ASP.NET look at:
| > System.Web.HttpApplication.Error event
| > Normally placed in your Global.asax file.
| >
| > For console applications look at:
| > System.AppDomain.UnhandledException event
| > Use AddHandler in your Sub Main.
| >
| > For Windows Forms look at:
| > System.Windows.Forms.Application.ThreadException event
| > Use AddHandler in your Sub Main.
| >
| > It can be beneficial to combine the above global handlers in your app,
as
| > well as wrap your Sub Main in a try catch itself.
| >
| > There is an article in the June 2004 MSDN Magazine that shows how to
| > implement the global exception handling in .NET that explains why & when
you
| > use multiple of the above handlers...
| >
| > http://msdn.microsoft.com/msdnmag/is...T/default.aspx
| >
| > For example: In my Windows Forms apps I would have a handler attached to
the
| > Application.ThreadException event, plus a Try/Catch in my Main. The
| > Try/Catch in Main only catches exceptions if the constructor of the
MainForm
| > raises an exception, the Application.ThreadException handler will catch
all
| > uncaught exceptions from any form/control event handlers.
| >
| > Public Shared Sub Main()
| > AddHandler Application.ThreadException, AddressOf
| > Application_ThreadException
| > Application.EnableVisualStyles()
| > Application.DoEvents()
| > Try
| > Application.Run(New MainForm)
| > Catch ex As Exception
| > '' log ex for later diagnosis
| > '' optionally show "pretty" version to user
| > End Try
| > End Sub
| >
| > Private Shared Sub Application_ThreadException(ByVal sender As
Object,
| > ByVal e As System.Threading.ThreadExceptionEventArgs)
| >
| > '' Log the e.Exception for later diagnosis.
| > '' optionally show "pretty" version to user
| >
| > End Sub
| >
| > Hope this helps
| > Jay
| >
| >
| >
| > "chopsnsauce" <ch*********@discussions.microsoft.com> wrote in message
| > news:BF**********************************@microsof t.com...
| > | Here''s the example:
| > |
| > | Dim frm As New FORM1
| > | Try
| > |
| > | frm.show
| > |
| > | Catch ex As Exception
| > |
| > | msgbox ex.message
| > |
| > | End Try
| > |
| > | Say FORM1 throws an exception in the load event. Run this in the
| > | Design-Time enviroment and the exception is caught by the code. Run
it in
| > | Run-Time and the exception is unhandled.
| > |
| > | Some people have said this is a bug. Can you (Microsoft) confirm this
for
| > | me please? And confirm whether its a bug in design or run-time? And
what
| > | the recomended work round for this is.
| > |
| > | Thanks,
| > |
| > | Nick Charnock
| > |
| > |
| > |
| > | ----------------
| > | This post is a suggestion for Microsoft, and Microsoft responds to the
| > | suggestions with the most votes. To vote for this suggestion, click
the "I
| > | Agree" button in the message pane. If you do not see the button,
follow
| > this
| > | link to open the suggestion in the Microsoft Web-based Newsreader and
then
| > | click "I Agree" in the message pane.
| > |
| > |
| >
http://www.microsoft.com/communities...t.languages.vb
| >
| >
| >


这篇关于设计时和运行时之间的异常处理差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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