B4J Code Snippet Sqlite version

Had to put this together quickly, seems to work ok, just thought I'd share...


B4X:
Sub GetSqliteVersion( db As SQL ) As String

	Try
		Return db.ExecQuerySingleResult( "SELECT sqlite_version();" )
	Catch
		Log(LastException)
		Return ""
	End Try
	
End Sub
 

B4JExplorer

Active Member
Licensed User
Longtime User
I don't see any reason to catch errors here.
We can't imagine an error, because the sql statement is already confirmed. But we can imagine a developer sending the wrong sql object, perhaps one where the connection has been lost.

I agree, it's unlikely Erel. But this is a just in case situation.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
But we can imagine a developer sending the wrong sql object
In that case it is better to let the error "bubble up". It will be easier for the developer to fix.

As a general rule you should avoid catching errors in libraries or utility methods and let the developer using the code decide how to handle errors.
 

B4JExplorer

Active Member
Licensed User
Longtime User
In that case it is better to let the error "bubble up". It will be easier for the developer to fix.

As a general rule you should avoid catching errors in libraries or utility methods and let the developer using the code decide how to handle errors.
Will do.

Actually, I never liked Try-Catch. It gets in the way of clean code, and makes error management more complicated than it has to be. GoLang is on the right track.
 
Top