No stacktrace exceptions in console under Xcode 4.2 / iOS 5?

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]); // Because iOS 5 doesn't provide a traceback, provide one here NSLog(@"Stack trace: %@", [exception callStackSymbols]); // Let Flurry look at the error [FlurryAPI logError:@"Uncaught" message:@"Crash!" exception:exception]; } 

(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; } 
+47
Nov 11 '11 at 21:13
source share
3 answers

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; } 

For ARC:

 int main(int argc, char *argv[]) { int retVal = -1; @autoreleasepool { @try { retVal = UIApplicationMain(argc, argv, nil, nil); } @catch (NSException* exception) { NSLog(@"Uncaught exception: %@", exception.description); NSLog(@"Stack trace: %@", [exception callStackSymbols]); } } return retVal; } 

Some explanation is still waiting for why the default dump no longer works and / or why the (even more serious) uncaughtExceptionHandler does not work. However, apparently, this problem only affects the emulator.

update:

It was pointed out that if you go to "Product β†’ Scheme β†’ Edit Scheme", select "Run (Debug)", select the "Diagnostics" tab and click "Log Exceptions", this will restore the missing Xcode to the default logging exception, maybe (I still did not try), eliminating the need for the aforementioned hack.

+35
Sep 04 '12 at 17:18
source share

This is a known issue ... for workarounds see here and here .

Another option might be

 defaults write NSGlobalDomain NSExceptionHandlingMask 63 

Although for OSX this may be useful when using the emulator - I can not try it now :-(

+2
Nov 14 '11 at 13:03
source share

I had the same problem and it worked for me "Compile for Thumb". Note. I just returned it for Debug configuration for obvious reasons.

+1
Jan 25 '12 at 21:45
source share



All Articles