O'Reilly logo

Xcode 4 Cookbook by Steven F. Daniel

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

Handling runtime errors

In this recipe, we will learn how to handle runtime errors within an iOS application.

Getting ready

In this section, we will learn how we can handle runtime errors and learn how we can improve error handling using the @try…@catch…@finally clauses to prevent our application from crashing.

How to do it...

To begin, follow the following simple steps as outlined:

  1. Open the MemoryLeaks.xcodeproj project file.
  2. Open the ViewController.m implementation file from the Project Navigator window.
  3. Modify the viewDidLoad method as shown by the highlighted code sections in the following code snippet:
    - (void)viewDidLoad
    {
       [super viewDidLoad];
      [self causeRuntimeError];
    }
  4. Next, create the causeRuntimeError method as shown in the following code snippet: ...

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