R
Rob Meade
Hi all,
Ok - typically, in a function that returns as a boolean, if there's a bit of
database action going on I'll have a little tidy up process before exiting
the function.
I know .net is supposed to handle all of this stuff itself, but its a
practice I've always performed, and personally I like to know its been done!
So, as an example I'd have a little something like this..
Private Function testMeDo(ByVal myObject As Object) As Boolean
Dim Connection As SQLConnection
Dim Command As SQLCommand
Dim Parameters As ArrayList
' exception handling
Try
' do some database wizardy here...
' then tidy up (same as below) <--- no squiggles in here because
I've created instances of the objects and populated them
Catch ex As Exception
' tidy up
If Parameters Is Nothing = False Then
Parameters.Clear()
Parameters = Nothing
End If
If Command Is Nothing = False Then
Command.Dispose
Command = Nothing
End If
If Connection Is Nothing = False Then
Connection.Close()
Connection = Nothing
End If
End Try
End Function
Ok - now this is just a "quick" example - but, because I haven't created new
instances of of the objects I've declare outside of the Try within the
"Catch" section of my Try/Catch - it places a green squiggle under them and
tells me that it might generate a Null exception error...
Whilst this doesn't have a detrimental effect on my application (yet at
least!) - I'd like it to be "tidier" and therefore not have the squiggles!
Any thoughts anyone?
Cheers
Rob
Ok - typically, in a function that returns as a boolean, if there's a bit of
database action going on I'll have a little tidy up process before exiting
the function.
I know .net is supposed to handle all of this stuff itself, but its a
practice I've always performed, and personally I like to know its been done!
So, as an example I'd have a little something like this..
Private Function testMeDo(ByVal myObject As Object) As Boolean
Dim Connection As SQLConnection
Dim Command As SQLCommand
Dim Parameters As ArrayList
' exception handling
Try
' do some database wizardy here...
' then tidy up (same as below) <--- no squiggles in here because
I've created instances of the objects and populated them
Catch ex As Exception
' tidy up
If Parameters Is Nothing = False Then
Parameters.Clear()
Parameters = Nothing
End If
If Command Is Nothing = False Then
Command.Dispose
Command = Nothing
End If
If Connection Is Nothing = False Then
Connection.Close()
Connection = Nothing
End If
End Try
End Function
Ok - now this is just a "quick" example - but, because I haven't created new
instances of of the objects I've declare outside of the Try within the
"Catch" section of my Try/Catch - it places a green squiggle under them and
tells me that it might generate a Null exception error...
Whilst this doesn't have a detrimental effect on my application (yet at
least!) - I'd like it to be "tidier" and therefore not have the squiggles!
Any thoughts anyone?
Cheers
Rob