在OC用try catch finally捕获异常,把可能出现异常的地方使用,比如访问数组的时候,在用perform系列方法的时候建议加上,可以捕获到找不到方法的异常,不会使程序崩溃。
@try {
NSString *a=(NSString *)[NSNullnull];
if ([aintegerValue]) {
NSLog(@"%@",[NSNullnull]);
}else{
NSLog(@"%@",[NSNullnull]);
}
NSLog(@"@try");
} @catch (NSException *exception) {
NSLog(@"%@",exception);
} @finally {
NSLog(@"@finally");
}
使用友盟之后如果友盟拦截全局异常的开关打开,友盟就能拦截全局的异常。当然,也可以自己收集这些异常信息,方法就是使用NSSetUncaughtExceptionHandler(&UncaughtExceptionHandler);
void UncaughtExceptionHandler(NSException *exception) {
/**
* 获取异常崩溃的堆栈信息
*/
NSArray *callStack = [exception callStackSymbols];
NSString *reason = [exception reason];
NSString *n