Point number 3 can be solved without adding strang...
# announcements
j
Point number 3 can be solved without adding strange syntax
Copy code
inline fun <T : Closeable?, R> T.tryUse(block: (T) -> R, exceptionHandler: (Exception) -> Unit): R {
    var closed = false
    try {
        return block(this)
    } catch (e: Exception) {
        closed = true
        try {
            this?.close()
        } catch (closeException: Exception) {
        }
        exceptionHandler(e)
        throw e
    } finally {
        if (!closed) {
            this?.close()
        }
    }
}

fun main(args: Array<String>) {
    val x = X()
    x.tryUse({
        println("doin something")
    }, {
        println("it died :(")
    })
}