UserControl - 例外 [英] UserControl - Exceptions

查看:66
本文介绍了UserControl - 例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用UserControls并对UserControls和VS.Net 2003中的异常行为提出疑问。


我注意到当UserControl从事件中抛出异常

(即Click事件)时,VS.Net将在确切的行上进入调试模式

抛出异常在UserControl中。您可以看到完整的调用堆栈

直到Click事件,来自Click事件的所有局部变量等。

但是,如果从Paint事件抛出异常,VS.Net将在Application.Run(new Form1())之后的行上输入
调试模式;在父母

表格中。调用堆栈中唯一的信息是Main()方法,而你

不知道什么行代码抛出异常,也无法访问本地的

变量绘制事件。


显然,Click事件中异常的信息比Paint事件中的异常信息更有用。

。 />

以下是重现此行为的方法:


1.创建一个名为ExceptionTest的新C#windows应用程序

2。创建一个名为ExceptionControl1的新UserControl

3.为Click事件和Paint事件添加事件处理程序

4.将以下代码行添加到click事件中:

抛出新的OverflowException();

5.构建项目

6.将ExceptionControl1添加到Form1

7。运行项目

8.当你单击放置ExceptionControl1的区域时,将抛出一个

异常并且VS.net调试器sh你可以直接点击事件代码来获得


9.停止调试并将一行代码从Click事件移动到

绘制事件。

10.运行项目

11.应用程序应该抛出异常immediatley并且VS.Net

调试器应该转储你在Form1.Main()方法。非常没用。


我的问题是,为什么会出现差异,如何在异常时使用VS.Net开始在Paint方法中调试
被抛出?

I''m just starting to work with UserControls and have a question on the
behavoir of exceptions within UserControls and VS.Net 2003.

I have noticed that when a UserControl throws an exception from an event
(i.e. Click event), VS.Net will enter debug mode on the exact line that
threw the exception in the UserControl. You can see the complete call stack
up to the Click event, all local variables from the Click event, etc.
However, if an exception is thrown from the Paint event, VS.Net will enter
debug mode on the line following Application.Run(new Form1()); in the parent
form. The only information in the call stack is the Main() method and you
have no clue as to what line of code threw the exception nor access to local
variable from the Paint event.

Obviously the information from an exception in the Click event is much more
useful than the information from an exception in the Paint event.

Here is how to reproduce this behavior:

1. Create a new C# windows application called ExceptionTest
2. Create a new UserControl called ExceptionControl1
3. Add an event handler for the Click event and Paint event
4. Add the following line of code to the click event:
throw new OverflowException();
5. Build the project
6. Add the ExceptionControl1 to Form1
7. Run the project
8. When you click the area where you placed the ExceptionControl1 an
exception will be thrown and the VS.net debugger should take you right to
the Click event code.
9. Stop debugging and move the one line of code from the Click event to the
Paint event.
10. Run the project
11. The application should throw an exception immediatley and the VS.Net
debugger should dump you in the Form1.Main() method. Pretty useless.

My question is, why is there a difference and how can I use VS.Net to begin
debugging within the Paint method when an exception is thrown?

推荐答案

你好杰夫。


我们已经审查了这个问题,目前正在研究它。我们将尽快更新您的b $ b。感谢您的耐心等待!


Kevin Yu

=======

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

权利。

Hi Jeff.

We have reviewed this issue and are currently researching on it. We will
update you ASAP. Thanks for your patience!

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




" Jeff" < a@a.com>在消息中写道

新闻:ef ************** @ TK2MSFTNGP14.phx.gbl ...

"Jeff" <a@a.com> wrote in message
news:ef**************@TK2MSFTNGP14.phx.gbl...
我只是开始使用UserControls并对UserControls和VS.Net 2003中的异常行为提出疑问。

我注意到当UserControl从事件中引发异常时
(即点击事件),VS.Net将在确认的行中进入调试模式,该行在UserControl中引发异常。您可以看到完整的调用
叠加到Click事件,来自Click事件的所有局部变量等。
但是,如果从Paint事件抛出异常,VS.Net将进入
在Application.Run(new Form1())之后的行上的调试模式;在
父表格中。调用堆栈中唯一的信息是Main()方法,你不知道什么行代码抛出异常,也没有从Paint事件访问
局部变量。
<显然,Click事件中异常的信息比Paint事件中的异常信息更有用。

以下是重现此行为的方法:
2.创建一个名为ExceptionControl1的新UserControl
3.为Click事件和Paint事件添加事件处理程序
4 。将以下代码行添加到click事件:
抛出新的OverflowException();
5.构建项目
6.将ExceptionControl1添加到Form1
7.运行项目
8.当您单击放置ExceptionControl1的区域时,将抛出异常,VS.net调试器应该右转到Click事件代码。
9.停止调试a nd将一行代码从Click事件移动到
Paint事件。
10.运行项目
11.应用程序应该抛出异常immediatley和VS.Net 调试器应该将您转储到Form1.Main()方法中。非常没用。

我的问题是,为什么会出现差异,如何在抛出异常时使用VS.Net来
在Paint方法中开始调试?
I''m just starting to work with UserControls and have a question on the
behavoir of exceptions within UserControls and VS.Net 2003.

I have noticed that when a UserControl throws an exception from an event
(i.e. Click event), VS.Net will enter debug mode on the exact line that
threw the exception in the UserControl. You can see the complete call stack up to the Click event, all local variables from the Click event, etc.
However, if an exception is thrown from the Paint event, VS.Net will enter
debug mode on the line following Application.Run(new Form1()); in the parent form. The only information in the call stack is the Main() method and you
have no clue as to what line of code threw the exception nor access to local variable from the Paint event.

Obviously the information from an exception in the Click event is much more useful than the information from an exception in the Paint event.

Here is how to reproduce this behavior:

1. Create a new C# windows application called ExceptionTest
2. Create a new UserControl called ExceptionControl1
3. Add an event handler for the Click event and Paint event
4. Add the following line of code to the click event:
throw new OverflowException();
5. Build the project
6. Add the ExceptionControl1 to Form1
7. Run the project
8. When you click the area where you placed the ExceptionControl1 an
exception will be thrown and the VS.net debugger should take you right to
the Click event code.
9. Stop debugging and move the one line of code from the Click event to the Paint event.
10. Run the project
11. The application should throw an exception immediatley and the VS.Net
debugger should dump you in the Form1.Main() method. Pretty useless.

My question is, why is there a difference and how can I use VS.Net to begin debugging within the Paint method when an exception is thrown?




可能是因为winform库包含对

中paint事件的调用,它自己的try-catch处理程序,可能在wndproc的级别它本身。


您应该能够通过将其设置为在第一次机会异常时中断来抛出

异常的行上弹出调试器。要执行此操作,请将

导入VS 2003并转到菜单Debug\Exceptions。将打开一个对话框,其中包含

树视图控件。 Highlite标题为公共语言运行时

例外的节点。底部是2个无线电控制。将顶部设置为

,其中显示Break into the debugger"并选择确定。


调试器现在应该在Paint例程中断行,抛出

异常。




Probably because the winform library wraps the call to the paint event in
its own try-catch handler, perhaps at the level of the wndproc itself.

You should be able to have the debugger pop up on the line that throws the
exception by setting it to break on 1st chance exceptions. To do this, go
into VS 2003 and go to menu "Debug\Exceptions". A dialog will open with a
treeview control in it. Highlite the node titled "Common Language Runtime
Exceptions". At the bottom are 2 radio controls. Set the top to the line
that says "Break into the debugger" and select OK.

The debugger should now break on the line in the Paint routine that throws
the exception.





" Kevin Yu [MSFT]" <,V - **** @ online.microsoft.com>在消息中写道

news:eN ************** @ cpmsftngxa10.phx.gbl ...

"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:eN**************@cpmsftngxa10.phx.gbl...
嗨杰夫。

我们已经审核了这个问题,目前正在研究它。我们会尽快给您更新。感谢您的耐心等待!

Kevin Yu
=======
此帖子已提供按现状没有保证,也没有授予
权利。
Hi Jeff.

We have reviewed this issue and are currently researching on it. We will
update you ASAP. Thanks for your patience!

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




太棒了!期待收到您的回复!



Great! Looking forward to hearing back from you!


这篇关于UserControl - 例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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