试试Catch ......需要我的大脑嘎嘎作响。 [英] Try Catch...need my brain rattled.

查看:51
本文介绍了试试Catch ......需要我的大脑嘎嘎作响。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在离开它之后尝试再次回到.net。


我试图通过尝试找出处理多个事件的正确方法

catch。


我很困惑的是处理3个单独的

事件的正确方法: A,B和C.如果所有3个都能成功执行
,我只希望所有3个执行。


这就是try-catch的用途,或者是主要针对个人

事件的尝试/捕获?


是否有最佳实践方法来处理3个单独事件的检查并且

只有在所有3都可以无误执行的情况下才执行所有3?


-Darrel

Trying to get back into .net again after being out of it for a while.

I''m trying to figure out the proper way to handle multiple events via a try
catch.

What I''m confused about is the proper method to handle, say, 3 separate
events: A, B, and C. I only want all 3 to execute if all 3 can successfully
execute.

Is that what a try-catch is for, or is a try/catch mainly for individual
events?

Is there a best-practice way to handle checking for 3 separate events and
only executing all 3 only if they all can execute without error?

-Darrel

推荐答案

即使有多次捕获,你也可以在try catch中有三个动作

如果有任何失败,它会直接进入捕获,你可以弹出
$ b那时$ b程序。

darrel < no ***** @ notreal.comwrote in message

news:%2 **************** @ TK2MSFTNGP04.phx.gbl .. 。
You could have three actions within a try catch even with multiple catches
If any fail it would go directly to the catch and you could pop outta the
procedure at that point.
"darrel" <no*****@notreal.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...

试图在离开它之后再次回到.net。


我是试图找出通过

尝试捕获来处理多个事件的正确方法。


我很困惑的是正确处理的方法,比方说,3个单独的

事件:A,B和C.如果所有3个人都能成功执行
,我只希望所有3个执行。

这是尝试捕获的原因,还是主要针对个人

事件的尝试/捕获?


有没有最好的-practice方法来处理3个独立事件的检查和

只有在它们都可以无误执行的情况下才执行所有3个?


-Darrel
Trying to get back into .net again after being out of it for a while.

I''m trying to figure out the proper way to handle multiple events via a
try catch.

What I''m confused about is the proper method to handle, say, 3 separate
events: A, B, and C. I only want all 3 to execute if all 3 can
successfully execute.

Is that what a try-catch is for, or is a try/catch mainly for individual
events?

Is there a best-practice way to handle checking for 3 separate events and
only executing all 3 only if they all can execute without error?

-Darrel



尝试... Catch无法处理事件,它处理您的

代码引发的异常。


如果你想编写一个公共事件处理程序(当多个事件触发时,一个名为

的程序),你需要将程序注册为事件

处理程序。在VB .NET中,它很简单:只需扩展Handles即可。

现有事件处理程序的子句,带逗号并列出你想要的其他事件

句柄:


Public Sub multiEventHandler (ByVal sender As System.Object,e As EventArgs)

_

处理Button1.Click,Button2.Click,Button3.Click


在C#中,它涉及的更多一些。您需要转到Page的Init事件

并将程序注册为特定事件的处理程序:


button1.Click + = button_click()

button2.Click + = button_click()

button3.Click + = button_click()


-Scott


" darrel" < no ***** @ notreal.comwrote in message

news:%2 **************** @ TK2MSFTNGP04.phx.gbl .. 。
Try...Catch doesn''t handle events, it handles exceptions raised by your
code.

If you want to write a common event handler (one procedure that is called
when multiple events fire), you need to register the procedures as event
handlers. In VB .NET, it''s easy: just extend the "Handles" clause of an
existing event handler with a comma and list the other events you wish to
handle:

Public Sub multiEventHandler(ByVal sender As System.Object, e As EventArgs)
_
Handles Button1.Click, Button2.Click, Button3.Click

In C#, it''s a bit more involved. You''d need to go to the Page''s Init event
and register the procedures as handlers for a particular events:

button1.Click += button_click()
button2.Click += button_click()
button3.Click += button_click()

-Scott

"darrel" <no*****@notreal.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...

试图在离开它之后再次回到.net。


我是试图找出通过

尝试捕获来处理多个事件的正确方法。


我很困惑的是正确处理的方法,比方说,3个单独的

事件:A,B和C.如果所有3个人都能成功执行
,我只希望所有3个执行。

这是尝试捕获的原因,还是主要针对个人

事件的尝试/捕获?


有没有最好的-practice方法来处理3个独立事件的检查和

只有在它们都可以无误执行的情况下才执行所有3个?


-Darrel
Trying to get back into .net again after being out of it for a while.

I''m trying to figure out the proper way to handle multiple events via a
try catch.

What I''m confused about is the proper method to handle, say, 3 separate
events: A, B, and C. I only want all 3 to execute if all 3 can
successfully execute.

Is that what a try-catch is for, or is a try/catch mainly for individual
events?

Is there a best-practice way to handle checking for 3 separate events and
only executing all 3 only if they all can execute without error?

-Darrel



即使有多次捕获,你也可以在try catch中有三个动作
You could have three actions within a try catch even with multiple catches

如果有任何失败,它将直接进入捕获,你可以在那时弹出

程序。
If any fail it would go directly to the catch and you could pop outta the
procedure at that point.



对,但那只是按顺序检查它们,对吗?例如:


尝试

A()

B()

C()< br $>
catch

结束尝试


即使C失败,A和B也可以执行?


-Darrel

Right, but that would merely check them sequentially, correct? for example:

Try
A()
B()
C()
catch
end try

A and B could execute even if C fails?

-Darrel


这篇关于试试Catch ......需要我的大脑嘎嘎作响。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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