How i finding Internate network error using Try..........Catch in iphone?

Posted by Rajendra Bhole on Stack Overflow See other posts from Stack Overflow or by Rajendra Bhole
Published on 2010-03-12T07:14:25Z Indexed on 2010/03/12 7:17 UTC
Read the original article Hit count: 182

Filed under:

Hi, I developing an application in which i calling web services on iphone. I want to implement Try.......Catch in that code for catching internet and GPRS connection error.The code is as follow, NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease]; [request setURL:[NSURL URLWithString:mainURL5]]; [request setHTTPMethod:@"POST"];

NSHTTPURLResponse* urlResponse = nil;  
NSError *error = [[[NSError alloc] init] autorelease];  
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];  
result5 = [[NSMutableString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];  

I was using Try......catch but it didn't work that code as follows, @try { //prepar request NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease]; [request setURL:[NSURL URLWithString:mainURL5]]; [request setHTTPMethod:@"POST"];

NSHTTPURLResponse* urlResponse = nil;  
NSError *error = [[[NSError alloc] init] autorelease];  
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];  
result5 = [[NSMutableString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
}
@catch(NSException * e)
{
    [clsMessageBox ShowMessageOK:@"some text" :[e reason]];
}

© Stack Overflow or respective owner

Related posts about iphone