本文转载至 http://blog.csdn.net/remote_roamer/article/details/7105776
- 抛出错误的代码
[cpp] view plaincopy
- //如果返回的报文是错误信息,则抛出错误
- if([outParams count] <= 0)
- {
- [NSException raise:@"WebService error" format:@"%@", returnJson4SOAP];
- }
- 在调用中捕获错误代码
[cpp] view plaincopy
- //从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-11-08 08:59:04