Error handling is the process of responding to and recovering from error conditions within our applications. Prior to Swift 2.0, error reporting followed the same pattern as Objective-C; however, with Swift, we have the added benefit of using optional return values, where returning a nil would indicate an error within the function.
In the simplest form of error handling, the return value from the function would indicate whether it was successful or not. This return value could be something as simple as a boolean true/false value or something more complex such as an enumeration whose values indicated what actually went wrong if the function was unsuccessful. If we needed to report additional information about the error that occurred, we could add an NSError
out parameter of the NSErrorPointer
type, but this wasn't the easiest approach and these errors tended to be ignored by developers. The following example illustrates how errors were generally handled prior...