XCode中main.m直接crash

问题描述

**2015-11-03 17:50:27.798 Periferica[12033:4104907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[1]'**
***** First throw call stack:**
**(0x18499cf48 0x19954ff80 0x18488b7c8 0x18488b660 0x1000414d4 0x100041150 0x189fa5324 0x18a1d3acc 0x18a1d7e0c 0x18a1d4f50 0x18e7bb7c4 0x18e7bbb44 0x184954544 0x184953fd8 0x184951cd8 0x184880ca0 0x189f9e1c8 0x189f98ffc 0x1000416f4 0x199d9e8b8)**
**libc++abi.dylib: terminating with uncaught exception of type NSException**

解决方法
xcode gdb/lldb调试命令ps:主要学到的是bt
ios崩溃的解决
iOS捕获异常,常用的异常处理方法
让XCode的 Stack Trace信息可读
整理平时IOS调试中遇到的问题

相关代码
方法一:main.m文件

int main(int argc, char * argv[]) {
  @autoreleasepool {
    int retVal;
    @try {
      retVal = UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
    @catch (NSException *exception) {
      NSLog(@"CRASH: %@", exception);
      NSLog(@"Stack Trace: %@", [exception callStackSymbols]);
    }
    @finally {
      NSLog(@"finally");
    }
    return retVal;
  }
}

方法二:AppDelegate

void uncaughtExceptionHandler(NSException *exception) {
  /**
   *  获取异常崩溃信息
   */
  NSArray *callStack = [exception callStackSymbols];
  NSString *reason = [exception reason];
  NSString *name = [exception name];
  NSString *content = [NSString stringWithFormat:@"========异常错误报告========\nname:%@\nreason:\n%@\ncallStackSymbols:\n%@",name,reason,[callStack componentsJoinedByString:@"\n"]];
  
  /**
   *  把异常崩溃信息发送至开发者邮件
   */
  NSMutableString *mailUrl = [NSMutableString string];
  [mailUrl appendString:@"[email protected]"];
  [mailUrl appendString:@"?subject=程序异常崩溃,请配合发送异常报告,谢谢合作!"];
  [mailUrl appendFormat:@"&body=%@", content];
  // 打开地址
  NSString *mailPath = [mailUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  [[UIApplication sharedApplication] openURL:[NSURL URLWithString:mailPath]];
}

遗留问题:
当错误来自第三方库的时候你就懵了。

你可能感兴趣的:(XCode中main.m直接crash)