commonMain.Cleanup.kt Maven / Gradle / Ivy
package ch.softappeal.yass2
/** Calls the specified function [block], adds the thrown exception to `this` and returns `this`. */
public inline fun E.addSuppressed(block: () -> Unit): E {
try {
block()
} catch (e: Exception) {
addSuppressed(e)
}
return this
}
public inline fun tryFinally(tryBlock: () -> R, finallyBlock: () -> Unit): R {
var exception: Exception? = null
try {
return tryBlock()
} catch (e: Exception) {
exception = e
throw exception
} finally {
exception?.addSuppressed(finallyBlock) ?: finallyBlock()
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy