1、-[ViewController test]: unrecognized selector sent to instance 0x7fd763e083d0
ViewController沒有實(shí)現(xiàn)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可以調(diào)用此方法,可避免出現(xiàn)奔潰,但key不會(huì)添加進(jìn)去
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
[dict setValue:nil forKey:@"testKey"];
3、*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil
數(shù)組不能添加值為nil的obj
NSMutableArray *array = [NSMutableArray array];
[array addObject:nil];
4*** -[__NSArrayM objectAtIndexedSubscript:]: index 0 beyond bounds for empty array
數(shù)組越界
NSMutableArray *array = [NSMutableArray array];
array[0];
5、Thread 1: EXC_BAD_ACCESS (code=2, address=0x7ffee4401ff8)
遞歸調(diào)用
- (void)viewDidLoad {
[self viewDidLoad];
}
6、EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
向一個(gè)已經(jīng)release的對(duì)象發(fā)送消息
- (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這個(gè)循環(huán)一過就銷毀了
[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
給一個(gè)沒有實(shí)現(xiàn)copy協(xié)議的對(duì)象使用copy關(guān)鍵字修飾,賦值就會(huì)出現(xiàn)崩潰
-----
@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;