I Kotlin you'd write some inline function that encapsulated your domain specific cach/wrap logic. Let's call it "sqlContext". You'll use it in your SQL methods like this:

fun querySomething(param: String) =

sqlContext(param) {

// the actual query

}

This way you avoid writing try/catch in general code, remove boilerplate and implement centralized handling for SQL errors. You can also easily incorporate a context that would close all open results sets, thus avoiding try-with-resource boilerplate on each SQL operation, too.

Written by

Project Lead for the Kotlin Programming Language @JetBrains

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store