In Xcode 3.x and iOS 4, if an unhandled exception is signaled in the emulator, there is an exception stack trace (similar to Java) on the console output.
When I raise an unhandled exception in iOS 5 in Xcode 4.2 using the same application code, no stack trace occurs. (I figured out how to set an exception checkpoint, but this does not create tracing in the console.)
Is this just an Xcode parameter that I need to do somewhere, or a βfunctionβ of Xcode 4 / iOS 5? Is there a way to restore this bit of functionality?
Update
Unfortunately, adding uncaughtExceptionHandler does not work. Here is the handler:
void uncaughtExceptionHandler(NSException *exception) { NSLog(@"uncaughtExceptionHnadler -- Exception %@", [exception description]);
(Turns out he was already present to do the Flurry thing, so I just added a stack trace.)
Here it is included (just a few lines below where the handler is declared):
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Enable uncaught exception handler to dump stack and let Flurry log the exception NSUncaughtExceptionHandler* hdlr = NSGetUncaughtExceptionHandler(); NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler); NSUncaughtExceptionHandler* newHdlr = NSGetUncaughtExceptionHandler(); // TODO: Test NSException* ex = [NSException exceptionWithName:@"AssertionFailure" reason:@"Test" userInfo:nil]; @throw ex;
I set breakpoints so that I can check the two values ββof the resulting handler. The first one is zero, and the second is apparently a valid address. But when a test exception is thrown, the handler (in the iOS 5 simulator) never gets control. (Although when I run the iOS 4.2 simulator, it takes control.)
Setting NSExceptionHandlingMask seems to be impossible on the iPhone. The ExceptionHandling.framework prerector is not available.
Update 2
It works:
int main(int argc, char *argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int retVal = -1; @try { retVal = UIApplicationMain(argc, argv, nil, nil); } @catch (NSException* exception) { NSLog(@"Uncaught exception: %@", exception.description); NSLog(@"Stack trace: %@", [exception callStackSymbols]); } [pool release]; return retVal; }