The code provided below is not working as expected due to the order of the catch blocks. Your task is to fix the code so that each exception is properly caught and handled.
Catching supertype
Bring order
Report a typo
Sample Input 1:
HelloSample Output 1:
You did not enter a valid integer!Sample Input 2:
0Sample Output 2:
You cannot divide by zero!Write a program in Kotlin
fun main() {
val input = readln()
try {
println(100 / input.toInt())
} catch (e: Exception) {
println("An unknown error has occurred!")
} catch (e: NumberFormatException) {
println("You did not enter a valid integer!")
} catch (e: ArithmeticException) {
println("You cannot divide by zero!")
}
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.