Note that there are some explanatory texts on larger screens.

plurals
  1. POMy Objective-C exceptions don't cause my app to terminate, but Apple's do
    text
    copied!<p>In my iOS (iPhone/cocos2d) project, I'm finding that exceptions I throw myself aren't causing the app to terminate (they just cause the current function to exit, which leads to weird half-frozen behavior). For example, the following code causes a crash:</p> <pre><code>NSArray* testArray = [NSArray arrayWithObjects:@"One", @"Two", @"Three", nil]; [testArray objectAtIndex:400]; </code></pre> <p>When I run that code, I get the following in the console, as I would expect:</p> <pre class="lang-none prettyprint-override"><code>2011-06-07 12:55:20.421 mansion-iphone[38184:207] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSArray objectAtIndex:]: index 400 beyond bounds [0 .. 2]' </code></pre> <p>However, if I try to raise an exception (e.g. from an assert), I get the half-freeze unless I've enabled "Stop on Objective-C exceptions". This is fine for me but causes problems when my testers report problems -- since the app didn't crash, they don't have a crash log to send me. Here's an example of an exception that doesn't work:</p> <pre><code>NSException* e = [NSException exceptionWithName:NSInternalInconsistencyException reason:[NSString stringWithFormat:@"%s %@", __PRETTY_FUNCTION__, [NSString stringWithFormat:@"Invalid argument"]] userInfo:nil]; [e raise]; </code></pre> <p>With "Stop on Objective-C exceptions" turned off, that doesn't even cause a message to the console -- using NSAssert instead gives me a console message but still no stop. So, it seems like exceptions generated by Cocoa classes are behaving correctly, but exceptions originated from my code aren't.</p> <p>I've checked my code and cocos2d and haven't found any @try blocks that would seem to prevent an exception; anybody have an idea?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload