How to get line number, method name, and class name when crash occurs using Objective C

主宰稳场 提交于 2019-12-05 06:33:41

问题


I am developing an app in which I have to track crashes. There is a restriction that I can't use any third party source like Twitter's Fabric framework to handle crash logging.

Currently I am only able to get the reason for crash. I am not able to get the exact point of crash.

What I am doing:

In my app delegate's didFinishLaunchingWithOptions method I had made my own exception handler:

    NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler); 

uncaughtExceptionHandler ----

void uncaughtExceptionHandler(NSException *exception) {
    NSLog(@"CRASH: %@", exception);
    NSLog(@"callStackSymbols: %@", [exception callStackSymbols]);
    NSLog(@"callStackReturnAddresses: %@", [exception callStackReturnAddresses]);
    NSLog(@"reason: %@", [exception reason]);
    NSLog(@"name: %@", [exception name]);    
    NSLog(@"%s %d %s %s", __FILE__, __LINE__, __PRETTY_FUNCTION__, __FUNCTION__);
// Internal error reporting
}

I crashed my app in viewDidLoad method using this:

   NSArray *myary;

   myary = [NSArray arrayWithObjects:@"sad", nil];

   NSString *str =  [myary objectAtIndex:22];

Here is my Stack Trace.

Is their any way to achieve what I want?

I tried following these solutions from SO but they don't give me any lead:

Solution 1

Solution 2

来源:https://stackoverflow.com/questions/37998489/how-to-get-line-number-method-name-and-class-name-when-crash-occurs-using-obje

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!