Disabling Error Propagation

suggest change

Swift’s error handling is meant to be explicit. A call that can throw must be preceded by try. try does not catch the error. It only marks that the function can throw.

For example, the following code uses a loadImage(atPath:) function, which loads the image resource at a given path or throws an error if the image can’t be loaded. In this case, because the image is shipped with the application, no error will be thrown at runtime, so it is appropriate to disable error propagation.

let photo = try! loadImage(atPath: "./Resources/John Appleseed.jpg")

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents