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

前端 未结 3 1541
礼貌的吻别
礼貌的吻别 2020-11-22 11:46

Under Xcode 3.x and iOS 4, if an unhandled exception is signaled in the emulator there is an exception stack trace (similar to Java\'s) produced in the console output.

<
相关标签:
3条回答
  • 2020-11-22 11:54

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

    Still waiting for some sort of explanation as to why the default dump no longer works and/or why (even more serious) uncaughtExceptionHandler doesn't work. However, apparently this problem only affects the emulator.

    update:

    It has been 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 default exception logging, possibly (I haven't tried it yet) eliminating the need for the above hack.

    0 讨论(0)
  • 2020-11-22 11:57

    I had the same issue, turning 'Compile for Thumb' back on worked for me. Note: I only turned it back on for the Debug configuration, for obvious reasons.

    0 讨论(0)
  • 2020-11-22 12:01

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

    Another option might be to

    defaults write NSGlobalDomain NSExceptionHandlingMask 63
    

    Although it is usually for OSX it might help when using the emulator - I can't try it right now though :-(

    0 讨论(0)
提交回复
热议问题