格式如下
@try {
statement
statement
...
}
@catch (NSException *exception) {
statement
statement
...
}
statement
statement
...
}
@catch (NSException *exception) {
statement
statement
...
}
int main (int argc, char *argv [])
{
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 drain];
return 0;
}
*** -[Fraction noSuchMethod]: unrecognized selector sent to instance 0x103280
Caught NSInvalidArgumentException: *** -[Fraction noSuchMethod]:
unrecognized selector sent to instance 0x103280
Execution continues!
沒有留言:
張貼留言