在ios开发中使用 try 和 catch 来捕获错误。
生活随笔
收集整理的這篇文章主要介紹了
在ios开发中使用 try 和 catch 来捕获错误。
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
轉載自: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;?? ????} ?
[cpp]?view plaincopy
[cpp]?view plaincopy
轉載于:https://www.cnblogs.com/viktyz/archive/2012/06/28/2872136.html
總結
以上是生活随笔為你收集整理的在ios开发中使用 try 和 catch 来捕获错误。的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SQLServer跟踪相关
- 下一篇: asp网页设计流量统计代码