12.6 Summary
In this chapter, you learned about errors in Swift, which is a major pillar of developing consistent applications. You have the option to throw built-in or custom errors, which are basically data types implementing the Error protocol. If you need to include custom descriptions, the LocalizedError protocol can be implemented instead.
The function throwing the error can implement a final cleanup code block using defer { … }, which is useful for tasks like closing files or concluding connections. Those blocks will execute even if the function ends with an error.
In the client code, you typically catch errors in do-try-catch blocks, where you can implement your error-handling logic. It’s also possible to ignore errors by using the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access