0

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];
} 
jscs
  • 63,694
  • 13
  • 151
  • 195
jim
  • 8,670
  • 15
  • 78
  • 149

1 Answers1

5

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.

Peter DeWeese
  • 18,141
  • 8
  • 79
  • 101
  • Ugh, that doesn't seem to work at all for me :( Have you tried to above code? Thanks for the input though. – jim Jun 20 '11 at 16:51
  • 2
    @Conor H - That was an answer to you question - it's a bug in the Simulator, and you're recommended to file a bug. Have you tried this cod on the device? – Abizern Jun 20 '11 at 17:52
  • Thanks guys, I can't try this yet as the iPad is out of the office but i'll mark this as answered. Thanks! – jim Jun 21 '11 at 08:22