iOS中异常处理机制使用小结

2021-08-19  本文已影响0人  奔跑的小蚂蚁_8b28

在iOS开发中经常会由于数组越界,添加数据为空,通信或者文件错误,内存溢出导致程序终端运行而引入异常处理机制。常用的处理方式是try catch机制。不过有几个专业术语需要解释,异常句柄、异常处理域断言。

@try {

    //Code that can potentially throw an exception 异常处理域 记述代码正常处理

    

} @catch (NSException *exception) {

    //Handle an exception thrown in the @try block 异常句柄 记录异常处理过程

} @finally {

    //Code that gets executed whether or not an exception is thrown 记录无论异常是否发生都会执行的代码

}

断言指的是代码正常运行满足的条件被破坏引发的异常,了解即可。目前的解决方案就是添加try catch,数组非空验证,索引数量验证,继续学习中。

上一篇下一篇

猜你喜欢

热点阅读