- 抛出错误的代码
//如果返回的报文是错误信息,则抛出错误 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; }
在ios开发中使用 try 和 catch 来捕获错误。
最新推荐文章于 2024-06-26 16:09:37 发布