O'Reilly logo

Swift Programming: The Big Nerd Ranch Guide by John Gallagher, Matthew Mathias

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 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 and ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required