0
0
iOS Swiftmobile~5 mins

Error handling (try, catch, throw) in iOS Swift - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Acatch
Btry
Cthrow
Ddo
What keyword is used to handle errors after a try statement?
Acatch
Bthrow
Cdo
Dtry
How do you signal an error inside a function in Swift?
Atry
Bcatch
Cthrow
Ddo
What is the purpose of a do-catch block?
ATo declare a throwing function
BTo ignore errors
CTo throw errors
DTo handle errors from throwing functions
What happens if you call a throwing function without using try?
ASwift gives a compile-time error
BSwift throws a runtime error
CThe function runs normally
DThe error is ignored
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.