Error Handling in Swift Flashcards
What are the two sides to handling errors within Swift? What do they involve?
- Triggering (or throwing) an error when the desired results are not achieved within the method of an iOS app.
- Catching and handling the error after it is thrown by a method.
The error type value can be of any type that conforms to what?
The ErrorType protocol
What is the “throws” keyword used for?
A method or function declares that it can throw an error using the “throws” keyword.
What does a “defer” statement do?
Allows a sequence of code statements to be declared as needing to be run as soon as the method returns.
Error types are created using values that conform to the ______ protocol and are most commonly implemented as __________.
ErrorType, enumerations
Methods and functions that throw errors are declared as such using the ______ keyword.
“throw”
The _____ and _____ statements are used within the body of methods and functions using the throw keyword to throw errors based on the ______
guard, throw, error type
A throwable method or function is called using the ____ statement which must be encapsulated within a _____ statement.
try, do-catch
What does a do-catch statement consist of?
A do-catch statement consists of an exhaustive list of catch pattern constructs, each of which contains the code to be executed in the event of a particular error being thrown.
What is a “defer” statements use?
Cleanup tasks can be defined to be executed when a method returns through the use of the “defer” statement.