Try Catch within While loop
I have a SQLite database that I wish to read records from and execute a piece of code against each record.
I am using a While loop with a Try Catch INSIDE it...
Code is as follows:-
result = slcom.ExecuteReader()
'TODO: There is a problem with this while loop whereby if an ex is caught the connection
' to the database is closed.
While result.Read
Try
< do some stuff here >
Catch ex As Exception
incrementFailoverCount(result("fid"))
End Try
End While
result.Close()
The problem is, once the Try block is entered and an ex is caught, the next iteration of the while loop fails, as it seems the minute an ex is caught the connection to 开发者_开发问答the SQLite database is closed, eventhough the connection properties state that it is open.
Any ideas ???
You can move all code within Try Catch into a function that return a boolean and takes a ByRef argument as result of the function
That function return value served as the indicator of the success or failed operation, ie exception being raised or not.
精彩评论