What if we have an try catch operator? (!:)

The !: operator would return a default value in case of exceptions

Example:

val n = "5.".toInt() !: 0 

should do the same as

fun String.toIntOrZero(): Int { return try { toInt() } catch(e: Exception) { 0 } } val n = "5.".toIntOrZero() 

submitted by /u/LootsKanattari
[link] [comments]