O'Reilly logo

Protocol-Oriented Programming with Swift by Jon Hoffman

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

Error handling with Swift 2

On the surface, exception handling in languages such as Java and C# may look very similar to Swift's new error handling pattern; however there are some significant differences. Developers accustomed to exception handling with these languages will notice these differences as they read this section. Before we explore how this error handling works, we need to see how we represent errors in this new error-handling pattern.

Representing errors

In Swift, errors are represented by values of types that conform to the ErrorType protocol. Swift's enumerations are very well suited for modeling these error conditions because, generally, we have a finite number of error conditions to represent. We can also use associated values to ...

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