Homework 10 - Exceptions, Try and Catch
Due: Monday, February 23, 2004

Introduction

This assignment asks you to write an interactive test driver for your Classroom class. It should handle the IOException and NumberFormatException, so that the main() method does not allow them to leak out. Specifically, a meaninful, helpful error message should be displayed.

Some Hints

I would suggest writing helper methods to get Strings, floats, &c. These methods can be called by your main and do the Exception handling and type conversions inside. They can, for example, print a meaningful error message. And, if you want to perform range checking, you can do this in a helper method, too. This way, your main is easier to read.

If you want, here's one trick you can use. Catch the exception within the helper method and print the error message. Then, re-throw it. This can be done like this:

catch (IOException ioe) { System.out.println ("Your message here."); throw ioe; }

Then, in main, catch the exception again -- and exit the program. You don't have to do this -- but it might help to structure your code in a much cleaner way. This is because main() always takes exactly the same action upon an exception -- it exits. And, we can still use exceptions to do the type-specific handling.