Here's my method:
- (IBAction)calculateButton:(id)sender {
NSInteger dividend = 0;
NSInteger divisor = 0;
@try {
dividend = [dividendField integerValue];
divisor = [divisorField integerValue];
[quotientField setIntegerValue: dividend / divisor]; //program crashes here
[remainderField setIntegerValue: dividend % divisor];
}
@catch (NSException *exception) {
NSAlert* alert = [[NSAlert alloc] init];
[alert setMessageText: @"Error"];
[alert setInformativeText: @"Invalid input!"];
[alert runModal];
}
}
The way I understood it NSException
is a general exception handler that all the other exceptions inherit from; so the question is, why does the program crash instead of going into the @catch
block? I get an EXC_ARITHMETIC
which by my understanding is still an exception... So why doesn't the @catch
catch it?