int main (int argc, const char * argv[]) { <br>
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int a1,b1,c1;
@try {
NSLog(@"Enter numerator: ");
scanf("%i",&a1);
NSLog(@"Enter denomenator: ");
scanf("%i",&b1);
c1 = a1/b1;
NSLog(@"%i",c1);
}
@catch (NSException * e) {
NSLog([e name]);
NSLog([e description]);
NSLog([e reason]);
}
@finally {
NSLog(@"inside finally block");
}
[pool drain];
return 0;
}
Here if i enter value of a1=10, b1=0, then there should be exception generated, so statement within catch block will supposed to be execute. But it doesn’t. Program crashed. Try..Catch doesn’t work in this case ……Looks like i am doing something wrong…
You are seeing the floating point exception which is caused by C code (c1 = a1/b1).
This is not wrapped in a NSException.
If you want to go through the catch block, you can replace your FPE code with
which will trigger a NSUnknownKeyException.