NSInvalidArgumentException objc_msgSend---SEL和具体参量都是objc_msgSend的参量
objc_msgSend NSInvalidArgumentException
SEL和具体参量都是objc_msgSend的参量,需要做合法性检查
NSInvalidArgumentException:
1、参数的合法性检查,在功能处理阶段;属于防御性编程问题。
1 libobjc.A.dylib 0x00007fff50ba89b2 objc_exception_throw + 48
2 CoreFoundation 0x00007fff23ecfa51 _CFThrowFormattedException + 194
3 CoreFoundation 0x00007fff23ece563 -[__NSArrayM insertObject:atIndex:].cold.1 + 35
4 CoreFoundation 0x00007fff23d50dcf -[__NSArrayM insertObject:atIndex:] + 1167
2、类型的函数查找,在函数路由查找阶段;属于类型安全问题;
1 libobjc.A.dylib 0x00007fff50ba89b2 objc_exception_throw + 48
2 CoreFoundation 0x00007fff23e5dc34 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x00007fff23e4190c ___forwarding___ + 1436
4 CoreFoundation 0x00007fff23e43bf8 _CF_forwarding_prep_0 + 120
5 DispatchGroupGo 0x00000001057a4ca2 -[ViewController viewDidLoad] + 98
Name of an exception that occurs when you pass an invalid argument to a method, such as a nil pointer where a non-nil object is required.
NSString *str = [NSNull null];
[str length];
-[NSNull length]: unrecognized selector sent to instance 0x7fff8062d9d0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull length]: unrecognized selector sent to instance 0x7fff8062d9d0'
NSArray *tp = @"";
[tp objectAtIndex:0];
-[__NSCFConstantString objectAtIndex:]: unrecognized selector sent to instance 0x10f7ab068
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString objectAtIndex:]: unrecognized selector sent to instance 0x10f7ab068'
NSArray *tpd = @[@"dd",@"dds"];
[tpd objectAtIndex:2];
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** __boundsFail: index 2 beyond bounds [0 .. 1]'
NSMutableArray *marr = [@[] mutableCopy];
[marr addObject:nil];
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
消息转发 – objc_msgFoward
通过 [target selector] 调用方法的时候,如果没有找到方法的实现 IMP,按照正常流程走的话,程序是会崩溃的,也就是我们经常碰到的一种 crash:
0 CoreFoundation 0x000000010a1ce1bb __exceptionPreprocess + 331
1 libobjc.A.dylib 0x0000000109291735 objc_exception_throw + 48 2 CoreFoundation 0x000000010a1ecf44 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132 3 CoreFoundation 0x000000010a1d2ed6 ___forwarding___ + 1446 4 CoreFoundation 0x000000010a1d4da8 _CF_forwarding_prep_0 + 120 5 MsgForwardDemo 0x0000000108974745 -[ViewController viewDidLoad] + 117 6 UIKitCore 0x000000010d3c44e1 -[UIViewController loadViewIfRequired] + 1186 ...
https://redye.github.io/2019/04/26/objc_msgForward/ |
相关文章
- 指尖上的电商---(5)schema.xml配置具体解释
- vue基础篇---生命周期
- Kubernetes笔记:深入kubernetes---日志和监控( Prometheus、Helm、PrometheusOperator、Grafana)
- Android 开源框架Universal-Image-Loader完全解析(一)--- 基本介绍及使用
- 微信小程序---账号注册与开发工具
- Ubuntu - 20.04系统安装乐鑫ESP-IDF工具链(2) --- 安装IDF
- Mysql学习---面试基础知识点总结
- 审计系统---堡垒机项目之用户交互+session日志写入数据库[完整版]
- 【leetcode】力扣 --- 日积月累,每日一题——8 长度最小的子数组
- 药品生产---验证管理规程
- Spring 3 MVC: Themes In Spring-Tutorial With Example---reference