How do you print out a stack trace to the console/log in Cocoa?

前端 未结 6 1349
旧巷少年郎
旧巷少年郎 2020-12-04 04:49

I\'d like to log the call trace during certain points, like failed assertions, or uncaught exceptions.

6条回答
  •  半阙折子戏
    2020-12-04 05:21

    n13's answer didn't quite work - I modified it slightly to come up with this

    #import 
    
    #import "AppDelegate.h"
    
    int main(int argc, char *argv[])
    {
        @autoreleasepool {
            int retval;
            @try{
                retval = UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
            }
            @catch (NSException *exception)
            {
                NSLog(@"Gosh!!! %@", [exception callStackSymbols]);
                @throw;
            }
            return retval;
        }
    }
    

提交回复
热议问题