Error Handling in Swift Flashcards

1
Q

What are the two sides to handling errors within Swift? What do they involve?

A
  1. Triggering (or throwing) an error when the desired results are not achieved within the method of an iOS app.
  2. Catching and handling the error after it is thrown by a method.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

The error type value can be of any type that conforms to what?

A

The ErrorType protocol

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the “throws” keyword used for?

A

A method or function declares that it can throw an error using the “throws” keyword.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does a “defer” statement do?

A

Allows a sequence of code statements to be declared as needing to be run as soon as the method returns.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Error types are created using values that conform to the ______ protocol and are most commonly implemented as __________.

A

ErrorType, enumerations

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Methods and functions that throw errors are declared as such using the ______ keyword.

A

“throw”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

The _____ and _____ statements are used within the body of methods and functions using the throw keyword to throw errors based on the ______

A

guard, throw, error type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

A throwable method or function is called using the ____ statement which must be encapsulated within a _____ statement.

A

try, do-catch

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does a do-catch statement consist of?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a “defer” statements use?

A

Cleanup tasks can be defined to be executed when a method returns through the use of the “defer” statement.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly