views:

59

answers:

1

I have been reading about exception handling on the Apple developer docs, but I was wondering why exceptions by standard C operations are not caught?

E.g. the code below still crashes the application, without catching the div by zero. Will the @try/@catch block only catch Obj-C code?

@try {
    int i = 10 / 0;
}
@catch (NSException * e) {
    NSLog(@"Div by zero!");
}
@finally {
    // Nothing...
}
+3  A: 

Division by zero isn't an exception of type NSException. In fact, it's not really an "exception" in terms of a programming language, either. C itself doesn't have any exceptions in the same way that C++, Java, etc., do. When division by 0 in C occurs, an "exception" is "thrown" by the processor, and handling for that error happens at a much lower level.

mipadi