先看下面一个例子

#import <UIKit/UIKit.h>

#import "AppDelegate.h"

@interface Something : NSObject

- (void)doWithError:(NSError **)outError;

@end

@implementation Something

- (void)doWithError:(NSError **)outError
{
@autoreleasepool
{
*outError = [NSError errorWithDomain:@"Emergency" code:999 userInfo:nil];
}
} @end int main(int argc, const char *argv[])
{
@autoreleasepool
{
NSError *error = nil;

     // Sometimes EXC_BAD_ACCESS when return from this method.
[[[Something alloc] init] doWithError:&error]; // At this point, the main thread gives EXC_BAD_ACCESS.
NSLog(@"%@", error);
}
return 0;
}

在NSLog输出的时候会EXC_Bad_ACCESS

正确写法应该是这样:

@interface Something : NSObject

- (void)doWithError:(NSError **)outError;

@end

@implementation Something

- (void)doWithError:(NSError **)outError
{
NSError *error = nil;
@autoreleasepool
{
error = [NSError errorWithDomain:@"Emergency" code:999 userInfo:nil];
// Do something
}
if(error)
{
*outError = error;
}
} @end int main(int argc, char * argv[])
{
@autoreleasepool
{
NSError *__autoreleasing error = nil; [[[Something alloc] init] doWithError:&error]; // At this point, the main thread gives EXC_BAD_ACCESS.
NSLog(@"%@", error); int a = 1;
++a;
}
return 0;
}

最新文章

  1. 《转载》使用org.w3c.dom.Element的setTextContent()、getTextContent()方法时出现编译错误
  2. *HDU 1757 矩阵乘法
  3. My Sql 中要Alter Table的同学请注意!!!
  4. Android Studio 2.2.2 发布
  5. IT蓝豹--RecyclerView加载不同view实现效果
  6. 配置android模拟器
  7. javascript高级函数
  8. BeautifulSoup 安装使用
  9. 关于UNION ALL与 UNION 用法和区别
  10. Oracle中Left join的on和where的效率差别
  11. 【.NET】转载:使用FileStream批量上传文件。
  12. JMeter之Throughput Controller详解(实验)
  13. 关于echarts
  14. 日期类的使用(java)-蓝桥杯
  15. 论文阅读(Weilin Huang——【ECCV2016】Detecting Text in Natural Image with Connectionist Text Proposal Network)
  16. C# 应用程序单例(禁止多开) 获取.net版本号 以及 管理员权限
  17. selenium环境搭建-python自动化脚本测试
  18. linux连接数过多,导致ping包丢包的问题解析
  19. springboot中velocity tool中注入bean
  20. leetcode-algorithms-20 Valid Parentheses

热门文章

  1. 利用ArcGIS Engine、VS .NET和Windows控件开发GIS应用
  2. 基数排序/Go实现
  3. 微信公众平台开发localStorage数据总是被清空
  4. css3 --- 翻页动画 --- javascript --- 3d --- 准备
  5. 二.JSP开发过程中遇到的问题及解决
  6. Epic - Snake Sequence
  7. 40个超酷的jQuery动画效果教程
  8. Java多线程学习总结--线程概述及创建线程的方式(1)
  9. BestCoder Round #88
  10. Ubuntu 下无法Tab键自动补全功能解决办法