Complete the code to mark the function as throwable.
func fetchData() [1] {
// code that might throw an error
}The throws keyword marks a function that can throw an error.
Complete the code to call a throwable function correctly.
do {
try [1]()
} catch {
print("Error occurred")
}Use try before calling a function that can throw an error, like fetchData().
Fix the error in the catch block to print the error description.
do {
try fetchData()
} catch [1] {
print(error.localizedDescription)
}The catch block must declare the error with let error to access it.
Fill both blanks to throw a custom error inside the function.
enum DataError: Error {
case [1]
}
func fetchData() throws {
throw DataError.[2]
}Define a custom error case notFound and throw it inside the function.
Fill both blanks to handle a specific error case in catch.
do {
try fetchData()
} catch DataError.[1] {
print("Data not found")
} catch [2] {
print("Other error: \(error)")
} catch {
print("Unknown error")
}Catch the specific notFound error, then catch other errors by declaring let error and printing it.
