« G5 2.5 vs 2.0 GHz | Main | Carmack does Java »

A little IMP oddity

This works in 10.3 but crashes in 10.2 In 10.2 you only see the messages from the first two NSLogs(non-IMP code)
#import <Foundation/Foundation.h>


int main (int argc, const char *argv[])
{
   NSAutoreleasePool   *pool;
   NSDictionary        *dictionary;
   IMP                 imp;

   pool = [[NSAutoreleasePool alloc] init];

   dictionary = [NSDictionary dictionaryWithObject:@"VfL"
                                            forKey:@"Bochum"];

NS_DURING
   [dictionary selectorThatDoesNotExist];
NS_HANDLER
   NSLog( @"Exception: %@", localException);
NS_ENDHANDLER
   NSLog( @"Calling unimplemented messages via objc_msgSend can be caught");

NS_DURING
   imp = [dictionary methodForSelector:@selector( selectorThatDoesNotExist)];
   (*imp)( dictionary, @selector( selectorThatDoesNotExist));
NS_HANDLER
   NSLog( @"Exception: %@", localException);
NS_ENDHANDLER
   NSLog( @"And calling them via IMP can also be caught");
 
   [pool release];
   return( 0);
}

About

This page contains a single entry from the blog posted on March 17, 2005 12:14 PM.

The previous post in this blog was G5 2.5 vs 2.0 GHz.

The next post in this blog is Carmack does Java.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type 3.34