jlleitschuh
12/22/2016, 2:59 AM/**
* 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:
{ statement.executeUpdate("DROP DATABASE ${db.dbName}") } doNotFail true
{ statement.executeUpdate("DROP ROLE ${db.username}") } doNotFail true
Also, that this is valid code is strange:
{}()
Reminds me of javascript's self executing functions.