Disabling Error Propagation
suggest changeSwift’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")
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents