美文网首页iOS开发精华专题移动开发iOS开发资料收集区
iOS开发异常处理,防止界面崩溃(使用@try、catch捕获异

iOS开发异常处理,防止界面崩溃(使用@try、catch捕获异

作者: Courage_SC | 来源:发表于2016-07-07 15:57 被阅读1823次

    在开发APP时,我们通常都会需要捕获异常,防止应用程序突然的崩溃,添加异常处理

    @try {
                // 可能会出现崩溃的代码
                // meg  = [MemberMeg parseFromData:data];
             } @catch (NSException *exception) {
              // 捕获到的异常exception
                  NSLog(@"main: Caught %@: %@", [exception name], [exception reason]);
                  dispatch_async(dispatch_get_main_queue(), ^{
                         DXAlertView *alert = [[DXAlertView alloc]initWithTitle:@"提示" contentText:[NSString stringWithFormat:@"未知错误,稍后再试"] leftButtonTitle:nil rightButtonTitle:@"确定"];
                         [alert show];
                        });
                    } @finally {
                        // 结果处理
                    }
    
    

    相关文章

      网友评论

      本文标题:iOS开发异常处理,防止界面崩溃(使用@try、catch捕获异

      本文链接:https://www.haomeiwen.com/subject/wddljttx.html