views:

147

answers:

2

Hi,

Why @try block do not work? It crash the app, but it was supposed to be catch by the @try block

 NSString* test = [NSString stringWithString:@"ss"];

 @try {
    [test characterAtIndex:6];

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

Thanks, Alex.

+3  A: 

Are you sure it is not something else because the exact code you have pasted above works fine.

2010-07-29 16:45:57.677 test[93103:207] Exception: *** -[NSCFString characterAtIndex:]: Range or index out of bounds
2010-07-29 16:45:57.678 test[93103:207] finally
objneodude
Thanks,I'll take a deeper look inside the problem.I've had some feeling that the code works fine,but the problem is somewhere else. Thanks again.
A: 

Now I've found the problem.

Removing the obj_exception_throw from my breakpoints solved this.Now it's catch by the @try block and also NSSetUncaughtExceptinHandler will handle this if a @try block is missing.

Thanks, Alex.

IF you hit continue when the debugger breaks, you should see the exception gets thrown and caught by your handler.
JeremyP