美文网首页
iOS中异常处理机制使用小结

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

作者: 奔跑的小蚂蚁_8b28 | 来源:发表于2021-08-19 08:34 被阅读0次

    在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,数组非空验证,索引数量验证,继续学习中。

    相关文章

      网友评论

          本文标题:iOS中异常处理机制使用小结

          本文链接:https://www.haomeiwen.com/subject/xbdobltx.html