Runtime Errors

Despite your best efforts, things will sometimes go wrong while your app is running. In Cocoa, these errors fall into two categories.

Programmer errors are situations that should never happen, which means that they are the result of, well, a mistake you made. (We say they should never happen… but we have made plenty of these.) Examples include not meeting the precondition of a method (the index was not within the array’s bounds), performing an illegal operation (such as force-casting incorrectly or force-unwrapping a nil), or sending a message to an Objective-C object that does not understand it.

Swift alerts you to programmer errors by trapping, which results in stopping the program. Cocoa APIs use Objective-C ...

Get Cocoa Programming for OS X: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.