Recall & Review
beginner
What is the purpose of try in Swift error handling?
The try keyword is used to call a function that can throw an error. It tells Swift to watch for errors and handle them if they occur.
Click to reveal answer
beginner
What does catch do in Swift?
catch is used to handle errors thrown by a try statement. It lets you respond to different errors and keep your app running smoothly.
Click to reveal answer
beginner
How do you throw an error in Swift?
You use the throw keyword followed by an error value to signal that something went wrong. This passes the error up to be handled by try and catch.
Click to reveal answer
intermediate
What is a do-catch block in Swift?
A do-catch block lets you try code that might throw errors inside the do section, and handle any errors in the catch section.
Click to reveal answer
intermediate
What happens if you call a throwing function without try?
Swift will give a compile-time error because it requires you to handle possible errors explicitly using try, try?, or try!.
Click to reveal answer
Which keyword do you use to call a function that might throw an error in Swift?
✗ Incorrect
You use try to call a function that can throw an error.
What keyword is used to handle errors after a try statement?
✗ Incorrect
catch handles errors thrown by try.
How do you signal an error inside a function in Swift?
✗ Incorrect
Use throw to signal an error.
What is the purpose of a do-catch block?
✗ Incorrect
A do-catch block lets you handle errors from throwing functions.
What happens if you call a throwing function without using try?
✗ Incorrect
Swift requires try to handle errors, otherwise it gives a compile-time error.
Explain how Swift uses try, catch, and throw to handle errors.
Think about how you ask for help when something goes wrong.
You got /3 concepts.
Describe a simple example of a function that throws an error and how you would call it safely.
Imagine a vending machine that can run out of snacks.
You got /4 concepts.