首页 > 移动平台 > 详细

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

时间:2014-07-06 13:09:08      阅读:368      评论:0      收藏:0      [点我收藏+]

本文转载至 http://blog.csdn.net/remote_roamer/article/details/7105776

    1. 抛出错误的代码
      1. //如果返回的报文是错误信息,则抛出错误  
      2.    if([outParams count] <= 0)  
      3.    {  
      4.        [NSException raise:@"WebService error" format:@"%@", returnJson4SOAP];  
      5.    }  
    2. 在调用中捕获错误代码
      1. //从soap 信息中解析出CusotmerDetail 对象  
      2.     @try  
      3.     {  
      4.         customerDetail = [[[SoapRtnJsonParser alloc] init] parse2CustomerDtail:[returnSoapXML dataUsingEncoding:NSUTF8StringEncoding]];  
      5.     }@catch (NSException * e) {  
      6.         NSLog(@"Exception: %@", e);  
      7.         UIAlertView * alert =  
      8.         [[UIAlertView alloc]  
      9.          initWithTitle:@"错误"  
      10.          message: [[NSString alloc] initWithFormat:@"%@",e]  
      11.          delegate:self  
      12.          cancelButtonTitle:nil  
      13.          otherButtonTitles:@"OK", nil];   
      14.         [alert show];  
      15.         [alert release];  
      16.         return;  
      17.     }  

在ios开发中使用 try 和 catch 来捕获错误。,布布扣,bubuko.com

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

原文:http://www.cnblogs.com/Camier-myNiuer/p/3825812.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!