Complex handling

Report a typo

There is a function suspiciousFunction, and for some reason, you suspect that an exception might occur in it.

Process the call of suspiciousFunction with the help of the try-catch-finally statement. If an exception occurs in the function, print the exception message.

In the case of IOException, print the following message instead: The IOException occurred.

In the final block, output Handling completed successfully!.

Tip: Use message to get information about the exception.

Write a program in Kotlin
import java.io.IOException
import java.lang.ArithmeticException

fun suspiciousFunction (param: Int) {
when (param) {
0 -> throw Exception("Some exceptions?")
1 -> throw ArithmeticException("Division by zero")
2 -> throw Exception("An exception occurred here")
3 -> throw IOException()
}
}

fun handleException (data: Int) {

suspiciousFunction(data)

}
___

Create a free account to access the full topic