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
Share this Page URL
Help

Chapter 11. Exception Handling > Catching Uncaught Exceptions

Catching Uncaught Exceptions

You can set up a special function to catch all unhandled exceptions by calling NSSetUncaughtExceptionHandler(fn_ptr), where fn_ptr is a pointer to a function (just like a standard pointer, except that it points to a function) of the form void NSUncaughtExceptionHandler (NSException *exception). So if you don’t handle an exception anywhere else, it will be handled in the NSUncaughtExceptionHandler function.

To catch uncaught exceptions:

1.
Create a file named main.m.

2.
In main.m, enter the code shown in Listing 11.19.

This code sets up the exception-handling function.

3.
Add your exception-handling code (Listing 11.20).

4.
Save main.m.

Now your code can catch previously uncaught exceptions.


  

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