Help: AirplaneFactory Continued with Finally


Help is available for each task, or you can go straight to the solution source code.

Task 1

Create a new exception class, AirplaneFactoryException, that extends Exception.
Create the class declaration, AirplaneFactoryException extends Exeption.

Task 2

Create a constructor for the new exception, that takes a String code and stores it in a variable.
Create a protected String variable, code. The constructor for the class takes its String argument and assigns it to code.

Task 3

Create a toString method that prints out the name of the Class and the code.
This method will override the standard Exception.toString method. Use the methods Object.getClass and Class.getName to get the name of the class.

Task 4

Modify the existing exceptions to inherit from the new superclass.
Instead of extending Exception, they will now extend AirplaneFactoryException.

Task 5

Write constructors for the existing exceptions, have them call the constructor of the new superclass.
Add the new constructors to the four existing exceptions. They will take a string argument, and call the superclass (AirplaneFactoryException) constructor with that argument using the super variable.

Task 6

Replace all existing catch expressions to catch AirplaneFactoryException and print out the exception using toString.
Instead of catching both EngineException and FrameException, the buildComponents method will only catch AirplaneFactoryException, and print out the exception using the toString method.

Task 7

In the methods buildAirplane and buildComponents, add a finally clause to print out an appropriate closing statement.
After the catch blocks, add a finally block. In the block, print out a statement to match the one at the beginning of the method.

Task 8

For all throw expressions, modify the construction of the exceptions by adding a suitable code, such as "ENGBAD".
Using the newly defined constructors, pass a String as an argument.

Task 9

Compile and run the application, check the output.
Compare the output with the expected behavior.

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