Time for action – getting started with basic error handling
To add some basic error handling, take a look at the following steps:
Open the
FileManager.m
file.Update the
registerPlainText
method to match the following piece of code:-(NSString *) registerPlainText:(NSString *)filename { if ([_dict valueForKey:filename] == nil) { NSError *error; NSString *path = [[NSBundle mainBundle] pathForResource:filename]; NSString *content = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:
&error
]; if (error != nil) { NSLog(@"Error while loading plain text file: %@", error); } return (NSString *) [self registerAsset:filename withContent:content]; } else { return (NSString *) [self registerAsset:filename withContent:nil]; } }
What just happened?
While try-catch blocks are available in Objective-C, it's generally not a good idea to use them as they are quite slow and they can become quite difficult...