代码之家  ›  专栏  ›  技术社区  ›  nevan king

如何查看nserror?

  •  51
  • nevan king  · 技术社区  · 15 年前

    最好的登录方式是什么? NSError ?

    - (void)checkThing:(Thing *)thing withError:(NSError *)error {
        NSLog(@"Error: %@", error);
    }
    

    给我一个 null 消息

    3 回复  |  直到 9 年前
        1
  •  109
  •   James    15 年前

    看着 NSError 文档告诉我您需要执行以下操作:

    NSLog(@"%@",[error localizedDescription]);
    

    然后,这将为您提供人类可读的输出

        2
  •  19
  •   Peter Hosey    15 年前
    NSLog(@"Error: %@", error);
    

    给我一个空消息

    然后 error nil ,不是nserrror实例。

        3
  •  2
  •   Abizern    15 年前

    这是我在开发过程中用来记录错误的一种粗略方法;(不适用于CocoaTouch)

    // Execute the fetch request put the results into array
    NSError *error = nil;
    NSArray *resultArray = [moc executeFetchRequest:request error:&error];
    if (resultArray == nil)
    {
        // Diagnostic error handling
        NSAlert *anAlert = [NSAlert alertWithError:error];
        [anAlert runModal];
    }
    

    NSalert负责显示错误。