Java Exceptions  «Prev  Next»

Java Exception handling - Exercise

Modify Java drawing program

Objective: Add the following elements to the drawing program you copied from the previous lesson:
  1. Create a new type of Exception, called a ShapeException.
  2. In makeShape(), if the shape type was not found, throw a ShapeException.
    (Hint: do you need to change the method declaration?)
  3. Handle the exception by simply returning from mousePressed().
When this runs without an uncaught exception, paste your solution into the text area below: