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

本文详细阐述了在处理SOAP报文时遇到错误情况的应对策略,包括如何识别错误、解析错误信息以及在调用过程中捕获并处理这些错误。通过实例展示了使用NSException进行异常处理,并在捕获到错误时显示错误信息提示用户。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值