Handling string conversion errors in user input

Report a typo

You are working on a Kotlin application where you're converting a String to an Integer using toInt() method. However, the users sometimes input strings that contain non-digit characters. Fill the blanks in the code to handle these incorrect user inputs, output a relevant message and continue with the application execution without crashing.

Fill in the gaps with the relevant elements
 {
    val number = "123a".toInt()
}  (e: ) {
    println("$e has been caught!")
}
NumberFormatExceptioncatchtry
___

Create a free account to access the full topic