Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (NSString *)fooFromPath:(NSString *)path error:(NSError **)anError {
- const char *fileRep = [path fileSystemRepresentation];
- int fd = open(fileRep, O_RDWR|O_NONBLOCK, 0);
- if (fd == -1) {
- if (anError != NULL) {
- NSString *description = nil;
- NSDictionary *uDict = nil;
- int errCode;
- if (errno == ENOENT) {
- description = NSLocalizedString(@"No file or directory at requested location", @"");
- errCode = MyCustomNoFileError;
- } else if (errno == EIO) {
- // Continue for each possible POSIX error...
- }
- // Make underlying error.
- NSError *underlyingError = [[[NSError alloc] initWithDomain:NSPOSIXErrorDomain
- code:errno userInfo:nil] autorelease];
- // Make and return custom domain error.
- NSArray *objArray = [NSArray arrayWithObjects:description, underlyingError, path, nil];
- NSArray *keyArray = [NSArray arrayWithObjects:NSLocalizedDescriptionKey,
- NSUnderlyingErrorKey, NSFilePathErrorKey, nil];
- NSDictionary *eDict = [NSDictionary dictionaryWithObjects:objArray
- forKeys:keyArray];
- *anError = [[[NSError alloc] initWithDomain:MyCustomErrorDomain
- code:errCode userInfo:eDict] autorelease];
- }
- return nil;
- }
- // ...
Add Comment
Please, Sign In to add comment