gpt4 book ai didi

objective-c - NSInvalidArgumentException 未被代码捕获

转载 作者:行者123 更新时间:2023-11-28 18:44:35 27 4
gpt4 key购买 nike

我正在使用选择器动态调用 Objective-C 中的函数。我的问题是,如果我传递了一个不存在的函数名,我的 @try/@catch block 没有捕捉到异常。

在控制台中,我得到了一个未捕获的 NSInvalidArgumentException 并且进一步向下我得到了一个未捕获的 NSException

我尝试在标准 @try/@catch block 中捕获这两种类型的异常,但它们没有注册。如果我 try catch NSInvalidArgumentException,Xcode 不会让我编译,因为它不是可识别的类型。

关于如何解决这个问题有什么想法吗?

@try {
SEL s = NSSelectorFromString(@"funName");
[self performSelector:s withObject: nil];
}
@catch (NSException/NSInvalidArgumentException exception) {
NSLog(@"ERROR: %@", [exception message/reason];
}

最佳答案

许多人认为这是一个错误。

参见 http://openradar.appspot.com/8081169

通过测试类似的代码,我可以让它在设备上运行,但不能在模拟器上运行。

关于objective-c - NSInvalidArgumentException 未被代码捕获,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6412263/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com