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

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

    1. 抛出错误的代码
      [cpp]  view plain copy
      1. //如果返回的报文是错误信息,则抛出错误  
      2.    if([outParams count] <= 0)  
      3.    {  
      4.        [NSException raise:@"WebService error" format:@"%@", returnJson4SOAP];  
      5.    }  
    2. 在调用中捕获错误代码
      [cpp]  view plain copy
      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.     }  

转载于:https://www.cnblogs.com/Camier-myNiuer/p/3825812.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值