Book Image

Sparrow iOS Game Framework Beginner's Guide

By : Johannes Stein
Book Image

Sparrow iOS Game Framework Beginner's Guide

By: Johannes Stein

Overview of this book

Table of Contents (20 chapters)
Sparrow iOS Game Framework Beginner's Guide
About the Author
About the Reviewers

Time for action – getting started with basic error handling

To add some basic error handling, take a look at the following steps:

  1. Open the FileManager.m file.

  2. 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...