繁体   English   中英

如何查看NSError?

[英]How can I view an NSError?

记录NSError的最佳方法是什么?

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

给我一个null信息

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

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

这应该给你人类可读的输出

 NSLog(@"Error: %@", error); 

给我一个空信息

然后errornil ,而不是NSError实例。

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

// 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负责显示错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM