问题描述
无论如何要从createFileAtPath"中获取更详细的错误数据,我有点期待 NSError?目前我正在使用 BOOL 返回值.
Is there anyway to get more detailed error data back from "createFileAtPath" I was kind of expecting an NSError? Currently I am using the BOOL return value.
success = [fileMan createFileAtPath:fileOnDisk contents:dBuffer attributes:nil];
if(success == YES) NSLog(@"FileCreated");
else {
NSLog(@"ERROR: Failed to create file");
return 1;
}
加里
推荐答案
我同意...我很想有一个接受 NSError 的函数!
I agree... I'd love to have a function for this that accepts NSError!
在这种情况下返回的错误通常是 errno.h
中声明的 POSIX 错误之一(errno
作为 Cocoa 或 Foundation 标头的一部分自动包含在内).
Errors returned in this case are usually one of the POSIX errors declared in errno.h
(errno
is automatically included for you as part of the Cocoa or Foundation headers).
要查看错误,请使用 errno.h
中的 strerror
函数并引用全局 errno
整数,该整数由低位设置-level POSIX io 出现问题时的功能:
To see the error, use the strerror
function from errno.h
and reference the global errno
integer, which is set by the low-level POSIX io functions when a problem occurs:
if (![fm createFileAtPath:@"/etc/foobar.txt" contents:data attributes:nil])
{
NSLog(@"Error was code: %d - message: %s", errno, strerror(errno));
}
// output will be: Error was code: 13 - message: Permission denied
错误代码常量列表在Cocoa 错误处理编程指南(除了 errno.h 标头本身).
The list of error code constants are listed in the in the Error Handling Programming Guide for Cocoa (in addition to the errno.h header itself).
这篇关于来自 createFileAtPath 的更详细错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!