【问题标题】:XCode: Exception. How to detect the cause?XCode:例外。如何检测原因?
【发布时间】:2014-04-29 16:39:17
【问题描述】:

Xcode 4.6.1 与 iOS 6.1。我正在使用带有 StackMob 的远程数据库。应用程序首先出现错误,在我单击播放几次后,它运行良好并与服务器通信正常。不确定如何发现问题,是否应该关注?

我有以下异常断点设置:

应用程序运行,然后在以下行停止:

   NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"User" inManagedObjectContext:self.managedObjectContext];
    [fetchRequest setEntity:entity];

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"email == %@", self.emailAddressField.text];
    [fetchRequest setPredicate:predicate];

    NSError *error = nil;
    NSArray *fetchedObjects = [[self managedObjectContext] executeFetchRequest:fetchRequest error:&error];

所以我将上面的行改为:

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
        NSEntityDescription *entity = [NSEntityDescription entityForName:@"User" inManagedObjectContext:self.managedObjectContext];
        [fetchRequest setEntity:entity];

        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"username == %@", self.usernameField.text];
        [fetchRequest setPredicate:predicate];

        [managedObjectContext executeFetchRequest:fetchRequest onSuccess:^(NSArray *fetchedObjects)
            {

现在当我运行程序时,我收到以下错误:

所以我点击播放按钮

我收到以下错误:

在我再次单击播放后,应用程序继续运行,就好像什么都没发生一样?我应该担心吗?

【问题讨论】:

  • 请将您的代码发布为文本,而不是图像。
  • 我尽可能多地添加代码,但我觉得我真的需要一些图片来说明。
  • @user1107173 +1 获取图片!

标签: ios xcode exception


【解决方案1】:

一旦调试器在异常上停止,您可以使用简单的 lldb 命令检查异常是什么。在此处选择线程 6 中的异常:

然后如果你在模拟器上运行类型:

po $eax

如果您在设备上运行:

po $r0  (for 32-bit)
po $x0  (for 64-bit)

你应该得到异常的描述。

【讨论】:

  • 每天学习新东西。谢谢你。 6 分钟的等待期结束后,我将标记为已回答。
【解决方案2】:

你已经有了这个代码:

NSError *error = nil;
NSArray *fetchedObjects = 
    [[self managedObjectContext] executeFetchRequest:fetchRequest error:&error];

所以你需要做的就是继续(没有断点)并允许错误记录自己:

if (!fetchedObjects)
    NSLog(@"%@", error.localizedDescription);

【讨论】:

    猜你喜欢
    • 2012-07-25
    • 2019-07-15
    • 1970-01-01
    • 1970-01-01
    • 2014-02-06
    • 2010-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多