iOS Development: Why isn't my try block catching the exception?
- by BeachRunnerJoe
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 *)"eLength 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!