Graphics Programs Reference
In-Depth Information
Now let's introduce an exception in Whereami . In WhereamiViewController.m ,
delete the entire implementation of doSomethingWeird :
- (void)doSomethingWeird
{
NSLog(@"Line 1");
NSLog(@"Line 2");
NSLog(@"Line 3");
}
But don't delete the line in initWithNibName:bundle: that sends the doSo-
methingWeird message.
Now WhereamiViewController no longer implements doSomethingWeird , so
when it sends this message to self , an unrecognized selector exception will be thrown.
Build and run the application.
Immediately after launch, the application will blow up. The debugger will show you
where (look for the green execution indicator), and the console will show you why. Notice
that the stack trace is a bit longer this time, and the method that caused the exception is
not at the top of the stack trace. This will sometimes be the case: your code supplies bad
data (like an unrecognized selector) to a method, and then somewhere within that meth-
od's implementation, the application crashes. To find the source of the error, look for the
methods you implemented in the stack trace. The culprit may not be at the top, but it will
certainly be one of yours.
Also notice that the compiler warned you that the method definition was not found for
doSomethingWeird ( Figure 4.14 ).
Figure 4.14 Unimplemented method warning
This warning means that you declared a method in the header file but did not implement
it. Now remove the declaration of doSomethingWeird from WhereamiViewCon-
troller.h .
@interface WhereamiViewController : UIViewController <CLLocationManagerDelegate>
 
 
Search WWH ::




Custom Search