0
点赞
收藏
分享

微信扫一扫

iOS 使用@try、@catch来捕获异常

沪钢木子 2021-09-19 阅读 49
@try {
            // 可能会出现崩溃的代码
            //NSArray *data = [ListModel objectArrayWithKeyValuesArray:json[@"dataList"]];
         } @catch (NSException *exception) {
          // 捕获到的异常exception
              NSLog(@"main: Caught %@: %@", [exception name], [exception reason]);
              dispatch_async(dispatch_get_main_queue(), ^{
                     UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"操作提示" message:@"系统出现问题,请稍后重试" preferredStyle:UIAlertControllerStyleAlert];
    [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NSLog(@"点击确定"); 
    }]];
    [self presentViewController:alert animated:YES completion:nil];
                    });
                } @finally {
                    // 结果处理
                    //回收资源
                }
举报

相关推荐

0 条评论