尝试Catch最后,指针和Vb.net 2005编译器警告 [英] Try Catch Finally , pointers and Vb.net 2005 compiler warnings
问题描述
编译器给出了警告96变量''cmdSource''在被赋予值b / b
之前使用。在运行时可能会产生空引用异常。
将cmdSource调暗为SQlClient.SQLDataReader
尝试
设置数据库读取和这样做。
Catch ex as system.exception
例外情况
最后
cmdSource.close()
结束尝试
看不出这种方式(假设希望明确关闭
)
如果你在try语句中昏暗,你就会超出最终范围。
是否有一种整洁的方法可以摆脱这些警告?我的(是Vb.net 2003)数据
acccess课程现在已经满满的。
谢谢
Bob
Bob,
这样就可以了。
Dim cmdSource为SQlClient .SQLDataReader = Nothing
或者,您可以关闭项目检查,打开属性页面,单击编译选项卡,然后单击无。
分配前使用变量的通知列表条件。
-
Carsten Thomsen
社区 - http://community.integratedsolutions.dk
" Bob" < bo*@nowhere.com>在消息中写道
news:uC ************** @ TK2MSFTNGP09.phx.gbl ...>编译器提供警告96变量''cmdSource''在被分配值之前使用。在运行时可能会产生空引用异常。
将cmdSource作为SQlClient.SQLDataReader进行调整
尝试
设置数据库读取并执行此操作。
Catch ex as system。异常
异常的东西在这里
最后
cmdSource.close()
结束尝试
看不出这个出路(假设有一个愿望)明确地关闭
最后)
如果你在try语句中黯然失色,那么你最终会超出范围。
有没有一种方法可以摆脱这些警告?我的(是Vb.net 2003)
数据
acccess课程现在已经满满的了。
谢谢
Bob
Bob,
将cmdSource调暗为SQlClient.SQLDataReader
尝试
设置数据库读取并执行此操作。
有点像
dim cmdSource As SQLClient.SQLDataReader = cmd.ExecuteReader()
我希望这会有所帮助,
Cor
Carsten,
Dim cmdSource为SQlClient.SQLDataReader = Nothing
这不是诀窍,它*隐藏*仅警告带有额外指令
必须要完成。
我认为最好纠正警告的内容。
Cor
Hi,
The compiler gives Warning 96 Variable ''cmdSource'' is used before it has
been assigned a value. A null reference exception could result at runtime.
Dim cmdSource as SQlClient.SQLDataReader
Try
Set up the database read and do it.
Catch ex as system.exception
exception stuff here
Finally
cmdSource.close()
End try
Can''t see a way out of this (Assuming a desire to explicity close in the
finally)
If you Dim inside the try statement you go out of scope in the finally.
Is there a tidy way to get rid of these warnings? My (was Vb.net 2003) Data
acccess class is now littered with them.
Thanks
Bob
Bob,
This will do the trick,
Dim cmdSource as SQlClient.SQLDataReader = Nothing
Alternatively, you can switch off this checking for a project, by opening
the Property Pages, clicking Compile tab, and clicking None on the
Notification list for the "Use of variable prior to assignment " condition.
--
Carsten Thomsen
Communities - http://community.integratedsolutions.dk
"Bob" <bo*@nowhere.com> wrote in message
news:uC**************@TK2MSFTNGP09.phx.gbl...Hi,
The compiler gives Warning 96 Variable ''cmdSource'' is used before it has
been assigned a value. A null reference exception could result at runtime.
Dim cmdSource as SQlClient.SQLDataReader
Try
Set up the database read and do it.
Catch ex as system.exception
exception stuff here
Finally
cmdSource.close()
End try
Can''t see a way out of this (Assuming a desire to explicity close in the
finally)
If you Dim inside the try statement you go out of scope in the finally.
Is there a tidy way to get rid of these warnings? My (was Vb.net 2003)
Data
acccess class is now littered with them.
Thanks
Bob
Bob,
Dim cmdSource as SQlClient.SQLDataReader
Try
Set up the database read and do it.
Something as
dim cmdSource As SQLClient.SQLDataReader = cmd.ExecuteReader()
I hope this helps,
Cor
Carsten,
Dim cmdSource as SQlClient.SQLDataReader = Nothing
This is not the trick, it *hides* only the warning with an extra instruction
that has to be done.
In my opinion is better to correct for what is warned.
Cor
这篇关于尝试Catch最后,指针和Vb.net 2005编译器警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!