R
Rob Meade
Hi all,
Ok - I've used the word gramatically - which I'm sure is incorect, however I
mean when VS2005 lists "warnings" like this one:
Warning 1 Variable 'Command' is used before it has been assigned a value. A
null reference exception could result at runtime.
Warning 2 Variable 'Connection' is used before it has been assigned a value.
A null reference exception could result at runtime.
Warning 3 Variable 'Command' is used before it has been assigned a value. A
null reference exception could result at runtime.
Warning 4 Variable 'Connection' is used before it has been assigned a value.
A null reference exception could result at runtime.
Now, in my code I often do this within the "catch" part of a try..catch if
I've used a database connection/command in the "Try" section;
' tidy up
If Command Is Nothing <> False Then
Command.Dispose()
Command = Nothing
End If
If Connection Is Nothing <> False Then
Connection.Close()
Connection = Nothing
End If
The reason I do this, I believe is for tidyness, its quite possible that if
an exception was caused I may have already created my connection object,
and/or my Command object, therefore I test to see if they are "something",
and if so deal with them appropriately..
Of course, now with its new gadgets VS reports problems because I've not
"something'd" them in the "Catch" although I have in the "Try"...
Any suggestions - is my coding bad? Is there a better way? Any info
appreciated, I'm trying to go for good coding practices you see
)
Rob
Ok - I've used the word gramatically - which I'm sure is incorect, however I
mean when VS2005 lists "warnings" like this one:
Warning 1 Variable 'Command' is used before it has been assigned a value. A
null reference exception could result at runtime.
Warning 2 Variable 'Connection' is used before it has been assigned a value.
A null reference exception could result at runtime.
Warning 3 Variable 'Command' is used before it has been assigned a value. A
null reference exception could result at runtime.
Warning 4 Variable 'Connection' is used before it has been assigned a value.
A null reference exception could result at runtime.
Now, in my code I often do this within the "catch" part of a try..catch if
I've used a database connection/command in the "Try" section;
' tidy up
If Command Is Nothing <> False Then
Command.Dispose()
Command = Nothing
End If
If Connection Is Nothing <> False Then
Connection.Close()
Connection = Nothing
End If
The reason I do this, I believe is for tidyness, its quite possible that if
an exception was caused I may have already created my connection object,
and/or my Command object, therefore I test to see if they are "something",
and if so deal with them appropriately..
Of course, now with its new gadgets VS reports problems because I've not
"something'd" them in the "Catch" although I have in the "Try"...
Any suggestions - is my coding bad? Is there a better way? Any info
appreciated, I'm trying to go for good coding practices you see
![Blush :blush: :blush:](/styles/default/custom/smilies/blush.gif)
Rob