April 2026
Intermediate
683 pages
25h 29m
English
We’ll start by exploring how to throw errors. This is the logical first step: If there’s no error thrown, then there’s nothing to catch and manage in your client code, right? In this section, you’ll learn to throw built-in Swift errors and advance from there.
The first hands-on example will be a function that throws an error in the Swift library. For this purpose, Listing 12.4 features the stringToUrl function, which attempts to convert the input string to an URL object. Note that the function signature contains the throws keyword, indicating that it may produce errors.
import Foundationfunc stringToUrl(_ input: String) throws -> URL { guard let url = URL(string: input) else { throw ...
Read now
Unlock full access