Finally!

Report a typo

There is a function in the scope that divides 10 by the passed number.

def divide10(n: Int): Int = 10 / n

Complete the code of the protectedDivide so that both in case of an error and in case of a successful division, the function prints: "The function has ended".

Sample Input 1:

1
0

Sample Output 1:

The function has ended
10
The function has ended
0
Write a program in Scala 3
def protectedDivide(n: Int): Int =
try {
divide10(n)
} catch {
case _: Exception => 0
} ???
___

Create a free account to access the full topic