再试一次Catch Quesiton [英] Try Catch Quesiton Again

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

问题描述

昨天在一则名为Try Catch Question的消息中,我得到了很多回复。

谢谢大家。在所有的烟雾消失之后,我想问题是

将Return True语句放在下面的代码块中,这是函数的一部分

。它应该在try块的末尾,如下面所示,

还是应该在End Try Block之后?或者它有所作为吗?


尝试

mySqlConnection.Open()

Dim Da1 As New SqlDataAdapter(" Select) JnlType,描述来自

JnlType",mySqlConnection)

Dim Ds As New DataSet(" X")

Da1.Fill(Ds)

返回True

Catch

MsgBox(填充数据集查询表时出现问题

for JnlType")

返回False

最后

如果mySqlConnection.State = ConnectionState.Open那么

mySqlConnection.Close ()

结束如果

结束尝试

In a message yesterday titled Try Catch Question I got numerous responses.
Thank you to all. After all the smoke clears I guess the question is where
to place the Return True statement in the block of code below that is part
of a function. Should it be at the end of the try block, as dipicted below,
or should it be after the End Try Block? Or does it make a difference?

Try
mySqlConnection.Open()
Dim Da1 As New SqlDataAdapter("Select JnlType, Description from
JnlType", mySqlConnection)
Dim Ds As New DataSet("X")
Da1.Fill(Ds)
Return True
Catch
MsgBox("There was a problem filling the Dataset for Lookup table
for JnlType")
Return False
Finally
If mySqlConnection.State = ConnectionState.Open Then
mySqlConnection.Close()
End If
End Try

推荐答案

我会设置一个布尔值在try中设置为true,在

catch中设置为false。然后在finally中,使用If语句根据布尔值返回正确的值



" Woody Splawn" < WO *** @ splawns.com>在消息中写道

新闻:%2 **************** @ TK2MSFTNGP12.phx.gbl ...
I would set up a Boolean that is set to true in the try and false in the
catch. Then in the finally, use an If statement to return the correct value
based on the Boolean.
"Woody Splawn" <wo***@splawns.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
在一个昨天发布的帖子名为Try Catch Question我收到了很多回复。
谢谢大家。在所有烟雾消失后,我想问题是
将Return True语句放在下面的代码块中,这是函数的一部分。它应该在try块的末尾,如下面的
,还是应该在End Try Block之后?或者它有所作为吗?

尝试
mySqlConnection.Open()
Dim Da1 As New SqlDataAdapter(" Select JnlType,Description
from JnlType",mySqlConnection )
Dim Ds As New DataSet(X)
Da1.Fill(Ds)
返回True
Catch
MsgBox(填充有问题)查找数据集
表为JnlType")
返回False
最后
如果mySqlConnection.State = ConnectionState.Open那么
mySqlConnection.Close()
结束如果结束尝试
In a message yesterday titled Try Catch Question I got numerous responses.
Thank you to all. After all the smoke clears I guess the question is where to place the Return True statement in the block of code below that is part
of a function. Should it be at the end of the try block, as dipicted below, or should it be after the End Try Block? Or does it make a difference?

Try
mySqlConnection.Open()
Dim Da1 As New SqlDataAdapter("Select JnlType, Description from JnlType", mySqlConnection)
Dim Ds As New DataSet("X")
Da1.Fill(Ds)
Return True
Catch
MsgBox("There was a problem filling the Dataset for Lookup table for JnlType")
Return False
Finally
If mySqlConnection.State = ConnectionState.Open Then
mySqlConnection.Close()
End If
End Try



没有区别。只是不要把它放在Finally块中。


尝试

返回True ----- OK

Catch

..........

最后

........

结束尝试


或结束后尝试


尝试

.........

Catch

..........

最后

....... 。

结束尝试


返回True -----------确定

Woody Splawn < WO *** @ splawns.com>在消息中写道

新闻:%2 **************** @ TK2MSFTNGP12.phx.gbl ...
It makes no difference. Just don''t put it in the Finally block.

Try
Return True -----OK
Catch
..........
Finally
........
End Try

Or after End Try

Try
.........
Catch
..........
Finally
........
End Try

Return True -----------OK
"Woody Splawn" <wo***@splawns.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
在一个昨天发布的帖子名为Try Catch Question我收到了很多回复。
谢谢大家。在所有烟雾消失后,我想问题是
将Return True语句放在下面的代码块中,这是函数的一部分。它应该在try块的末尾,如下面的
,还是应该在End Try Block之后?或者它有所作为吗?

尝试
mySqlConnection.Open()
Dim Da1 As New SqlDataAdapter(" Select JnlType,Description
from JnlType",mySqlConnection )
Dim Ds As New DataSet(X)
Da1.Fill(Ds)
返回True
Catch
MsgBox(填充有问题)查找数据集
表为JnlType")
返回False
最后
如果mySqlConnection.State = ConnectionState.Open那么
mySqlConnection.Close()
结束如果结束尝试
In a message yesterday titled Try Catch Question I got numerous responses.
Thank you to all. After all the smoke clears I guess the question is where to place the Return True statement in the block of code below that is part
of a function. Should it be at the end of the try block, as dipicted below, or should it be after the End Try Block? Or does it make a difference?

Try
mySqlConnection.Open()
Dim Da1 As New SqlDataAdapter("Select JnlType, Description from JnlType", mySqlConnection)
Dim Ds As New DataSet("X")
Da1.Fill(Ds)
Return True
Catch
MsgBox("There was a problem filling the Dataset for Lookup table for JnlType")
Return False
Finally
If mySqlConnection.State = ConnectionState.Open Then
mySqlConnection.Close()
End If
End Try



纠正我,如果我错了,但我不相信最后一节会允许

你返回一个值。

Correct me if I''m wrong but I don''t believe the finally section will allow
you to return a value.


这篇关于再试一次Catch Quesiton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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