objective-c 如何查看 NSError?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1559169/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 22:20:55 来源:igfitidea点击:
How can I view an NSError?
提问by nevan king
What's the best way to log an NSError?
登录 的最佳方式是NSError什么?
- (void)checkThing:(Thing *)thing withError:(NSError *)error {
NSLog(@"Error: %@", error);
}
Gives me a nullmessage
给我null发消息
回答by James Raybould
回答by Peter Hosey
NSLog(@"Error: %@", error);Gives me a null message
NSLog(@"Error: %@", error);给我一个空消息
Then erroris nil, not an NSError instance.
然后error是nil,而不是 NSError 实例。
回答by Abizern
Here's a rough method I use to log errors while developing; (Not for Cocoa-touch)
这是我在开发时用来记录错误的粗略方法;(不适用于 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 takes care of displaying the error.
NSAlert 负责显示错误。

