Fake comment

Report a typo

You have a function from the library (already in the task scope). You can't find the source code, but you know the prototype of the function. The library developer kindly left a comment, but we can't guarantee that the function will return only this error.

/*
 * The function can throw an IllegalArgumentException if the argument is incorrect
 */
def parseSpecialNumber(s: String): Int

Fix our tryPrintSpecialNumber function to fulfill the following conditions:

  1. If there is an IllegalArgumentException thrown by parseSpecialNumber, we throw the error back so that other code handles it
  2. If there is any other error, we print its message
  3. If the function is completed successfully, just print the result

Sample Input 1:

99999999999

Sample Output 1:

Something went wrong
Write a program in Scala 3
def tryPrintSpecialNumber(s: String): Unit =
println(parseSpecialNumber(s)) // change the code here
___

Create a free account to access the full topic