2

i am using the following code to catch an error when ind.row is not a valid value or sometimes it becomes nil

@try {
        if(ind.row<[[treeNode flattenElements] count])
        {
            [self.mTableView scrollToRowAtIndexPath:ind atScrollPosition:UITableViewScrollPositionTop animated:YES];
        }


    }
    @catch (NSException *e) {
        NSLog(@"%@",e);

    }   

but when this code executes sometimes this error is occuring

Assertion failure in -[NSIndexPath row], /SourceCache/UIKit_Sim/UIKit-1262.60.3/UITableViewSupport.m:1948`

what may be the reason for this error and why exception is not being handled

iamsult
  • 1,581
  • 1
  • 15
  • 21
sujith1406
  • 2,822
  • 6
  • 40
  • 60
  • I don't know about iphone, but, I think you should also add `@catch (Exception *ee) {` `NSLog(@"%@",ee);}` – Fahim Parkar Jan 16 '12 at 07:35
  • 3
    You shouldn't be trying to catch an assertion failure to begin with. Your `NSIndexPath` was created incorrectly. – Lily Ballard Jan 16 '12 at 07:36
  • @KevinBallard actually what i am doing is in textfielddidbeginediting i pass the index of that cell to a ivar called ind by ind=[[self.mTableView indexPathForCell:(UITableViewCell*)textField.superview] retain]; then in the keyboardwasshown method,i use the above code for the textfield to scroll up when keyboard appears,but this is giving errors like this – sujith1406 Jan 16 '12 at 07:42

3 Answers3

3

Assertions in iOS don't throw exceptions, so you can't catch them.

You are going to need to figure out what's wrong with your call to -row. My first guess would be that "ind" is already freed or something.

StilesCrisis
  • 15,972
  • 4
  • 39
  • 62
1

You'll have to check the index, generate and raise an exception on you own:NSException Class Reference

+ (void)raise:(NSString *)name format:(NSString *)format, ...
A-Live
  • 8,904
  • 2
  • 39
  • 74
1

actually it was already catching the exceptions...i had set the flag stop on objc exceptions.when i removed that it catching the exceptions.... as pointed out by @stilesCrisis the ind value was null at the time of this exception..sorry for the trble

sujith1406
  • 2,822
  • 6
  • 40
  • 60