libc++abi.dylib: terminate_handler unexpectedly threw an exception错误小结
来源:互联网 发布:户外主播用的什么网络 编辑:程序博客网 时间:2024/05/16 05:56
前言
我们在运行xcode工程时,有时候会遇到”libc++abi.dylib: terminate_handler unexpectedly threw an exception”错误,app莫名其妙就crash掉了,在控制台输入bt命令,查看调用堆栈,结果也是一头雾水:
分析
现在唯一的信息点是libc++abi.dylib,这个库到底是做什么的?从后缀看,是一个动态库,那么会不会是因为发生了一些动态错误?而按经验来看,一般的动态错误基本是因为动态类型错误引起,在object-c语言中,会发生动态类型错误的可能基本存在于不可变类型与可变类型之间的转换,那么我们的查错范围将优先限制在不可变类型与可变类型转换上,是否我们对一个不可变类型进行了修改操作?当然,编译器没有那么傻,如果直接对一个不可变类型进行修改操作,是会直接报错的,那么就剩下另一种可能,程序将一个不可变类型赋值给可变类型,然后对可变类型进行了修改操作,这样可以通过静态检查,但是动态运行的时候,就会发生类型错误。基于以上分析,我们可以跟踪断点,会发现程序在对mutable对象进行add、set等操作时挂掉,而这个对象实际上赋值的是一个不可变对象。常见的情况是把一个NSArray对象赋值给一个NSMutableArray对象,然后进行了delete、add等修改操作,或者把一个NSDictionary对象赋值给一个NSMutableDictionary对象,然后进行了set等操作。
解决
解决办法很简单,赋值的时候进行类型转换:
//mutableArr:可变数组 arr:不可变数组 //mutableDic:可变字典 dic:不可变字典 //赋值时,需要进行可变类型转换 mutableArr = [NSMutableArray arrayWithArray:arr]; mutableDic = [NSMutableDictionary dictionaryWithDictionary:dic];
1 0
- libc++abi.dylib: terminate_handler unexpectedly threw an exception错误小结
- libc++abi.dylib: terminate_handler unexpectedly threw an exception错误小结
- libc++abi.dylib: terminate_handler unexpectedly threw an exception错误小结
- libc++abi.dylib: terminate_handler unexpectedly threw an exception错误小结
- libc++abi.dylib: terminate_handler unexpectedly threw an exception错误小结
- libc++abi.dylib: terminate_handler unexpectedly threw an exception错误小结
- libc++abi.dylib: terminate_handler unexpectedly threw an exception错误解决方案
- libc++abi.dylib: terminate_handler unexpectedly threw an exception错误
- 151128libc++abi.dylib: terminate_handler unexpectedly threw an exception错误
- libc++abi.dylib: terminate_handler unexpectedly threw an exception错误
- libc++abi.dylib: terminate_handler unexpectedly threw an exception
- libc++abi.dylib: terminate_handler unexpectedly threw an exception 报错
- libc++abi.dylib: terminate_handler unexpectedly threw an exception 问题解决
- iOS libc++abi.dylib: terminate_handler unexpectedly threw an exception
- 解决libc++abi.dylib: terminate_handler unexpectedly threw an exception(1)
- libc++abi.dylib: terminate_handler unexpectedly threw an exception
- UIActionSheet :libc++abi.dylib: terminate_handler unexpectedly threw an exception
- libc++abi.dylib: terminate_handler unexpectedly threw an exception
- sonarqube应用
- Adb connection Error:远程主机强迫关闭了一个现有的连接
- 高效显示Bitmap1--->高效加载大图
- Axure 学习战略
- stm28335-pwm模块-及ccd的时序驱动模块的实现-编程问题——项目问题1
- libc++abi.dylib: terminate_handler unexpectedly threw an exception错误小结
- c++学习总结(一些零碎的小知识点)
- c++_primer_exercise_1331
- C#中的各种流
- 将form表单里的数据封装成对象 json2.js的例子 jquery的serialize方法转换空格为+号的解决方法
- http://blog.csdn.net/xufeng0991/article/details/36672535
- xshell中文乱码设置方法
- 【Java】利用文件输入输出流完成把一个文件夹内的所有文件拷贝的另一的文件夹的操作
- LKT4203 32位高性能RSA防盗版加密芯片