Guest User

Untitled

a guest
Jan 22nd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. - (NSString *)fooFromPath:(NSString *)path error:(NSError **)anError {
  2.  
  3. const char *fileRep = [path fileSystemRepresentation];
  4. int fd = open(fileRep, O_RDWR|O_NONBLOCK, 0);
  5.  
  6. if (fd == -1) {
  7.  
  8. if (anError != NULL) {
  9. NSString *description = nil;
  10. NSDictionary *uDict = nil;
  11. int errCode;
  12.  
  13. if (errno == ENOENT) {
  14. description = NSLocalizedString(@"No file or directory at requested location", @"");
  15. errCode = MyCustomNoFileError;
  16. } else if (errno == EIO) {
  17. // Continue for each possible POSIX error...
  18. }
  19.  
  20. // Make underlying error.
  21. NSError *underlyingError = [[[NSError alloc] initWithDomain:NSPOSIXErrorDomain
  22. code:errno userInfo:nil] autorelease];
  23. // Make and return custom domain error.
  24. NSArray *objArray = [NSArray arrayWithObjects:description, underlyingError, path, nil];
  25. NSArray *keyArray = [NSArray arrayWithObjects:NSLocalizedDescriptionKey,
  26. NSUnderlyingErrorKey, NSFilePathErrorKey, nil];
  27. NSDictionary *eDict = [NSDictionary dictionaryWithObjects:objArray
  28. forKeys:keyArray];
  29.  
  30. *anError = [[[NSError alloc] initWithDomain:MyCustomErrorDomain
  31. code:errCode userInfo:eDict] autorelease];
  32. }
  33. return nil;
  34. }
  35. // ...
Add Comment
Please, Sign In to add comment