Error handling for problem 9