B4J Question Result Set close on error

Philip Prins

Active Member
Licensed User
Longtime User
Hello,

Do you need to close the resultset or cursor when you use Try Catch ?

Example
Example:
Try

        Dim RS As ResultSet =
        
        Do While
        
        Loop
        
        
        RS.close
        
Catch
        RS.close 'Is this neccesary?
End Try
 

DonManfred

Expert
Licensed User
Longtime User
Try Dim RS As ResultSet = Do While Loop RS.close
the rs.close is never reached after the loop as it never ends....

B4X:
Dim RS As ResultSet =
Do While rs.NextRow
Loop
RS.close
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
It is probably an overkill.

Note that you can write it like this:
B4X:
Try

        Dim RS As ResultSet =
        
        Do While
        
        Loop
        
        
        
Catch
    Log(LastException)
End Try
  RS.close

Assuming that it is a local SQLite db then there is no real reason for an unexpected error to happen. If it is a remote db then you should use a pool and make sure to close the connection (which will close other resources as well).
 
Upvote 0
Top