All Downloads are FREE. Search and download functionalities are using the official Maven repository.

name.remal.java.lang.AutoCloseable.kt Maven / Gradle / Ivy

package name.remal

inline fun  T.use(block: (T) -> R): R {
    var closed = false
    try {
        return block(this)

    } catch (e: Exception) {
        closed = true
        try {
            this?.close()
        } catch (closeException: Exception) {
            e.addSuppressed(closeException)
        }
        throw e

    } finally {
        if (!closed) {
            this?.close()
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy