Stack trace or more info on unhandled exception in Xcode/iPhone

后端 未结 4 1715
慢半拍i
慢半拍i 2020-11-28 19:29

Excuse my ignorance, but something\'s been bugging me about the Xcode debugger when running iPhone applications in the iPhone Simulator.

Sometimes, when I mess somet

4条回答
  •  不思量自难忘°
    2020-11-28 20:13

    You can wrap your UIApplicationMain in a try/catch:

    int main(int argc, char *argv[]) {
        int retVal;
        NSAutoreleasePool * pool;
        @try
        {
        pool = [[NSAutoreleasePool alloc] init];
        retVal = UIApplicationMain(argc, argv, nil, nil);
        }
        @catch(NSException* e)
        {
            NSLog(@"%@", e.reason);
        }
        @finally
        {
        [pool release];
        }
        return retVal;
    }
    

    You should also look up into setting an assertion handler while debugging: NSAssertionHandler.

    Update: and also the unhandled exception handler: NSSetUncaughtExceptionHandler

提交回复
热议问题