NSException
情景
Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ’ -[__NSArrayM insertObject:atIndex:]: object cannot be nil’
* First throw call stack:…(省略)
上面这端打印信息,对于ios开发者来说,是再熟悉不过了!但很少思考,是谁抛出这些异常,帮助我们定位问题?我们能利用它搞点什么事情吗?
是谁
它就是NSException!
看看官方文档对NSException描述(这里只截取部分)。
An object that represents a special condition that interrupts the normal flow of program execution.
去掉第一个that后的限定词,“An object that interrupts the normal flow of program execution.”,英语不好,我这边直接理解为“一个可以中断程序执行的对象”,
加上去掉的that条件:“在特定条件下,一个可以中断程序执行的对象”,
瞬间感觉厉害了,可以中断程序!~~~~
基本使用
1.简单调用
- (void)viewDidLoad {
[super viewDidLoad];
NSDictionary * exceptionDic = [NSDictionary dictionar