How i finding Internate network error using Try..........Catch in iphone?
- by Rajendra Bhole
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]];
}