Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Exceptions

Exceptions are abnormal conditions that prevent a program from continuing with execution. Creating an exception is referred to as raising an exception or throwing an exception. Common situations that will raise an exception are actions like sending a message to an object that doesn’t respond to that message, or attempting to retrieve an object from an NSArray with an index that is outside the bounds of the array. If you don’t do anything to handle an exception, the exception causes the program to terminate.

Objective-C provides a mechanism to handle exceptions with the compiler directives @try, @catch, and @finally. Each of these directives introduces a block of code as shown in Listing 10.2.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint