NSInvalidArgumentException not being caught in code

我的未来我决定 提交于 2019-12-12 01:33:44

问题


I'm using selectors to dynamically call functions in Objective-C. My problem is that my @try/@catch block is not catching the exception if I pass an non-existent function name.

In the console I get an uncaught NSInvalidArgumentException and further down I get an uncaught NSException.

I have tried catching the the two types of exceptions in a standard @try/@catch block but they aren't registering. Xcode won't let me compile if I try to catch NSInvalidArgumentException as it's not a recognized type.

Any ideas on how to solve this?

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

回答1:


Many consider this to be a bug.

See http://openradar.appspot.com/8081169

By testing similar code, I can make it work on a device but not in the simulator.



来源:https://stackoverflow.com/questions/6412263/nsinvalidargumentexception-not-being-caught-in-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!