iOS Development: Why isn't my try block catching the exception?

Posted by BeachRunnerJoe on Stack Overflow See other posts from Stack Overflow or by BeachRunnerJoe
Published on 2011-01-08T20:48:16Z Indexed on 2011/01/08 20:53 UTC
Read the original article Hit count: 180

Filed under:
|
|
|

Hi. I have an exception being thrown in my code, but when I wrap it in an try/catch block, it doesn't get caught. The NSLog statement is never called in the catch block. Here's the code...

NSInteger quoteLength;
[data getBytes:(void *)&quoteLength range:NSMakeRange(sizeof(messageType), sizeof(quoteLength))];

@try 
{
    //Debugger stack trace shows an NSException being thrown on this statement
    NSData *stringData = [data subdataWithRange:NSMakeRange(sizeof(messageType) + sizeof(quoteLength), [data length])];
    NSString *quote = [[NSString alloc] initWithData:stringData encoding:NSUTF8StringEncoding];
    NSLog(@"received quote: %@",quote);
    [quote release];

}
@catch (NSException * e) 
{
    NSLog(@"Exception Raised: %@", [e reason]);
}

Why doesn't it get caught?

Thanks so much!

© Stack Overflow or respective owner

Related posts about iphone

Related posts about xcode