Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception handling in Obj-C

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...
}
like image 555
Jamie Chapman Avatar asked Apr 23 '10 18:04

Jamie Chapman


1 Answers

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.

like image 196
mipadi Avatar answered Oct 21 '22 23:10

mipadi