try { val parsedInt = str.toInt() println("$parsedInt") } catch (nfe: NumberFormatException) { // not a valid int }