NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
Fraction * f = [[Fraction alloc] init];
@try{
[f noSuchMethod];
}
@catch (NSException *exception){
NSLog (@"Caught %@%@", [exception name], [exception reason]);
}
NSLog (@"Execution continues!");
[f release];
[pool drains];
return 0;
Almost all NSException objects (and other types of exception objects) are created autoreleased, which assigns them to the nearest (in scope) autorelease pool.
——From "Exception Handling and Memory Management" in Apple's Handling Exceptions document
师兄果然说得不错,@出现的地方都很重要。