Handling exceptions, I found myself needing this handy little function :
inline fun exec(lambda: () -> Any): Boolean = try { lambda() ; true } catch(e:Exception) { false }
Does functions like that exist in Kotlin ? Is there idiomatic altenatives to the heavy try-catch-finnaly syntax ?
successfulboolean because different exceptions can be thrown in different error scenarios, allowing for different error handling.IllegalArgumentExceptionandNumberFormatException, as a way to swallow exceptions that you don't need to log because they indicate something that you expected might happen, like if you pass user input for some kind of validation.kotlin val isAudio = isAudioFile(source) && exec { m.setDataSource(source.canonicalPath) }setDataSource would throw if there was any problem of data avaibility