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

后端 未结 4 1693
慢半拍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:08

    Hey activa - for more information about runtime exceptions, you should be able to open the debugger console and see more information. I assume you've already done that, but just in case - you can get to it by selecting Run -> Console from the menu. I'm not sure why it doesn't come up automatically!

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2020-11-28 20:14

    If you add two breakpoints, you should be able to debug these exceptions. To do this, go to Run | Show | Breakpoints and create two global breakpoints (I do them globally because they are so useful in all my applications). The first should be named "objc_exception_throw" and its location should be "libobjc.A.dylib". The second should be "-[NSException raise]" and its location should be "CoreFoundation".

    Now, if you start debugging your application with breakpoints enabled, it should break on the throw of these exceptions. You should then be able to see the chain of events that led to the exception within the debugger.

    0 讨论(0)
  • 2020-11-28 20:26

    The lack of a stack trace is usually indicative of a problem with LLDB (debugger). I love LLDB, but when it comes to showing stack traces and breaking on the exception rather than main in iOS apps, it's a pain in the ass and has been for a few releases now. No idea why Apple hasn't addressed this yet. To fix it is a two-step process:

    1. Edit your current scheme and under the "Run" tab change the debugger from LLDB to GDB.
    2. Go to https://developer.apple.com/bugreporter/ and report the bug so Apple addresses it.
    0 讨论(0)
提交回复
热议问题