How do you print out a stack trace to the console/log in Cocoa?
This code works on any thread:
NSLog(@"%@", NSThread.callStackSymbols);
Returns an array containing the call stack symbols. Each element is an
NSString
object with a value in a format determined by thebacktrace_symbols()
function.
n13's answer didn't quite work - I modified it slightly to come up with this
#import <UIKit/UIKit.h>
#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;
}
}