I have a for loop.
for (i=0; i <= stringLength; i++) {
unichar currentCharacter = [string characterAtIndex:i];
...}
I understand from the documentation that characterAtIndex: will usually return a value of the type 'unichar' but if our index is out of bounds an NSRangeException is returned.
Being cautious, I'd like to check whether [string characterAtIndex:i] is returning an NSRangeException or not before assigning to return value to currentCharacter.
The first thing I tried was this:
if ([string characterAtIndex:i] != NSRangeException)
...but it doesn't work because, from my understanding, the method usually returns an int and I'm comparing it to NSRangeException, which is a string.
I thought about [string characterAtIndex:i] isKindOfClass:...] but that won't work because [string characterAtIndex:i] is not an NSObject. So, uh, how do I test for the exception?
Should I be testing for the exception? How do I test for the type of the returned value if it's sometimes a primitive and sometimes an NSObject?