Swift Error Handling Philosophy
Swift is designed to encourage safe, easy-to-read code, and its error-handling system is no different.
Any function that could fail must be marked with throws.
This makes it obvious from the type of a function whether or not you need to handle potential errors.
Swift also requires you to mark all calls to functions that might fail with try.
This gives a great benefit to anyone reading Swift code.
If a function call is annotated with try, you know it is a potential source of errors that must be handled.
If a function call is not annotated with try, you know it will never emit errors that you need to handle.
If you have used C++ or Java, it is important to note the differences between Swift error handling ...
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