AirplaneFactory Continued with Finally


Prerequisites

Due to the great sucess of the earlier AirplaneFactory simulation, a budget extension has been approved for further development. In this Magercise, two extensions are made to the factory:

A new exception, AirplaneFactoryException will be introduced to offer better error reporting and easier coding of the simulation. The new exception will be the new superclass of all factory exceptions, it will store an error code, and print that as well as the full exception name in a toString method.

And finally clauses will be added to properly print out the termination of the two main processes, buildAirplane and buildComponent.

The use of finally is covered in the course notes.

Work Location

Perform all work for this magercise in VisualAge project MageLang Magercises, package magercises.finallyclause.

If this project does not appear in your Workspace add it from the repository (if it exists there) or create a new project using this name.

Tasks

Perform the following tasks:

  1. Create a new exception class, AirplaneFactoryException, that extends Exception.

  2. Create a constructor for the new exception, that takes a String code and stores it in a variable.

  3. Create a toString method that prints out the name of the Class and the code.

  4. Modify the existing exceptions to inherit from the new superclass.

  5. Write constructors for the existing exceptions, have them call the constructor of the new superclass.

  6. Replace all existing catch expressions to catch AirplaneFactoryException and print out the exception using toString.

  7. In the methods buildAirplane and buildComponents, add a finally clause to print out an appropriate closing statement.

  8. For all throw expressions, modify the construction of the exceptions by adding a suitable code, such as "ENGBAD".

  9. Compile and run the application, check the output.

The task numbers above are linked to the step-by-step help page. Also available is a complete solution to the problem, and expected behavior, to demonstrate it.

Copyright © 1996-1997 MageLang Institute. All Rights Reserved.