您的位置:首页 > 移动开发 > IOS开发

在ios开发中使用 try 和 catch 来捕获错误。

2011-12-27 14:34 369 查看
抛出错误的代码

//如果返回的报文是错误信息,则抛出错误
if([outParams count] <= 0)
{
[NSException raise:@"WebService error" format:@"%@", returnJson4SOAP];
}

在调用中捕获错误代码

//从soap 信息中解析出CusotmerDetail 对象
@try
{
customerDetail = [[[SoapRtnJsonParser alloc] init] parse2CustomerDtail:[returnSoapXML dataUsingEncoding:NSUTF8StringEncoding]];
}@catch (NSException * e) {
NSLog(@"Exception: %@", e);
UIAlertView * alert =
[[UIAlertView alloc]
initWithTitle:@"错误"
message: [[NSString alloc] initWithFormat:@"%@",e]
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"OK", nil];
[alert show];
[alert release];
return;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: