This is pretty cool: ``` /** * Suppresses simple ...
# announcements
j
This is pretty cool:
Copy code
/**
 * Suppresses simple exceptions that may be thrown by this code executing.
 */
infix fun <R, T : () -> R> T.doNotFail(doNotThrow: Boolean): R? {
    try {
        return this()
    } catch (ex: Exception) {
        when (ex) {
            is RuntimeException,
            is SQLException -> {
                if (doNotThrow) {
                    logger.debug("Failure was suppressed", ex)
                    return null
                } else {
                    throw ex
                }
            }
            else -> throw ex
        }
    }
}
That allows this code to be valid:
Copy code
{ statement.executeUpdate("DROP DATABASE ${db.dbName}") } doNotFail true
{ statement.executeUpdate("DROP ROLE ${db.username}") } doNotFail true
Also, that this is valid code is strange:
Copy code
{}()
Reminds me of javascript's self executing functions.