Complete the code to throw an exception when the number is negative.
val number = -5 val result = if (number >= 0) number else throw [1]("Negative number")
Complete the code to throw an exception as an expression inside a function.
fun getPositiveNumber(number: Int): Int = if (number > 0) number else throw [1]("Number must be positive")
Fix the error in the code by completing the throw expression correctly.
val value = 10 val result = if (value < 0) throw [1]("Negative value") else value
Fill both blanks to throw an exception with a custom message when the input is zero.
fun checkInput(input: Int): Int {
return if (input != 0) input else throw [1]("Input cannot be zero: " + [2])
}Fill all three blanks to throw an exception as an expression inside a map operation.
val numbers = listOf(1, 2, 0, 4) val results = numbers.mapIndexed { [2], n -> if (n != 0) n else throw [1]("Zero found at index " + [2]) }.mapIndexed { [3], value -> value * 2 }
