app闪退原因

1、-[ViewController test]: unrecognized selector sent to instance 0x7fd763e083d0

ViewController没有实现test方法。

2、[<__NSDictionary0 0x604000013580> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key testKey.

往字典里面添加了value为nil的testKey

NSDictionary *dict = [NSDictionary dictionary];
 [dict setValue:nil forKey:@"testKey"];

可以改为NSMutableDictionary可以调用此方法,可避免出现奔溃,但key不会添加进去

NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:nil forKey:@"testKey"];

3、*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil

数组不能添加值为nil的obj

NSMutableArray *array = [NSMutableArray array];
    [array addObject:nil];

4*** -[__NSArrayM objectAtIndexedSubscript:]: index 0 beyond bounds for empty array

数组越界

 NSMutableArray *array = [NSMutableArray array];
    array[0];

5、Thread 1: EXC_BAD_ACCESS (code=2, address=0x7ffee4401ff8)

递归调用

- (void)viewDidLoad {
    [self viewDidLoad];
}

6、EXC_BAD_ACCESS (code=EXC_I386_GPFLT)

向一个已经release的对象发送消息

- (void)viewDidLoad {
    NSMethodSignature *signature = [self methodSignatureForSelector:@selector(viewtest:)];
   NSInvocation *invacation = [NSInvocation invocationWithMethodSignature:signature];
    invacation.target = self;
    invacation.selector = @selector(viewtest:);
    
    for (int i = 0; i<5; i++) {
        if (i == 1) {
            UIViewController *vc = [[UIViewController alloc]init];// vc这个循环一过就销毁了
            [invacation setArgument:&vc atIndex:2];
        }
    }
    [invacation retainArguments];//奔溃
    [invacation invoke];
}
- (void)viewtest:(UIViewController *)vc {
    
}

修改后

for (int i = 0; i<5; i++) {
        if (i == 1) {
            UIViewController *vc = [[UIViewController alloc]init];
            [invacation setArgument:&vc atIndex:2];
            [invacation retainArguments];
        }
    }
    [invacation invoke];

7、-[UIViewController copyWithZone:]: unrecognized selector sent to instance 0x7fa9ba705fc0

给一个没有实现copy协议的对象使用copy关键字修饰,赋值就会出现崩溃

-----
@property (nonatomic,copy)UIViewController *vc;
-----
UIViewController *vc = [[UIViewController alloc]init];
    self.vc = vc;

8、Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)

线程死锁

dispatch_sync(dispatch_get_main_queue(), ^{
        
    });

9、*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[NSJSONSerialization dataWithJSONObject:options:error:]: Invalid top-level type in JSON write'

异常么没有捕获

- (void)viewDidLoad {
    [NSJSONSerialization dataWithJSONObject:self options:0 error:nil];
}

修改后

- (void)viewDidLoad {
    @try {
        [NSJSONSerialization dataWithJSONObject:self options:0 error:nil];
    }@catch( NSException *e){
        NSLog(@"%@",e);
    }
}

Fundation定义的异常常量

NSGenericException;
NSRangeException;
NSInvalidArgumentException;
NSInternalInconsistencyException;
NSMallocException;
NSObjectInaccessibleException;
NSObjectNotAvailableException;
NSDestinationInvalidException;
NSPortTimeoutException;
NSInvalidSendPortException;
NSInvalidReceivePortException;
NSPortSendException;
NSPortReceiveException;
NSOldStyleException;
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容