Skip to content

Instantly share code, notes, and snippets.

@webdevotion
Created March 4, 2012 14:51
Show Gist options
  • Save webdevotion/1973361 to your computer and use it in GitHub Desktop.
Save webdevotion/1973361 to your computer and use it in GitHub Desktop.
error handling
- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError
{
todoItems = [NSPropertyListSerialization propertyListWithData:data options:NSPropertyListMutableContainers format:NULL error:outError];
BOOL errorFound = todoItems == nil;
if (errorFound)
{
NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
[userInfo setValue:@"Custom Error Description" forKey:NSLocalizedDescriptionKey];
[userInfo setValue:@"Custom Failure Reason" forKey:NSLocalizedFailureReasonErrorKey];
[userInfo setValue:@"Custom Recovery Suggestion" forKey:NSLocalizedRecoverySuggestionErrorKey];
NSError *myError =
[NSError errorWithDomain:@"My Custom Domain" code:41 userInfo:userInfo];
[NSApp presentError:myError];
*outError = [NSError errorWithDomain:NSCocoaErrorDomain code:NSUserCancelledError userInfo:nil];
}
return !errorFound;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment