CIS 35A: Introduction to Java Programming

Home | Green Sheet | Lectures | Assignments | FAQ | Grades | Students

Lab #12 (Exercise 13-4)

Create a custom class

Due Date: Thursday of Week 4
10 points

In this lab, you'll experiment with custom classes and chained exceptions.

  1. Create a custom checked exception class named TestException that contains two constructors: one that accepts no parameters and one that accepts a String message.

  2. Open the CustomTesterApp class.
  3. Add a statement to Method3 that throws a TestException without a message. (You'll also need to delete or comment out the last statement in Method3 or the compiler will flag it as unreachable.) Add the code necessary to catch this exception in Method2. The catch block should simply display a message at the console. Compile and run the program and observe its operation.

  4. Modify your solution so that a custom message is passed to the TestException and is then displayed in the catch block. Compile and run the program to be sure that the custom message is displayed.

  5. Add another constructor to the TestException class that accepts a Throwable object as a parameter.

  6. Add a try statement to Method3 of the CustomTesterApp class. The try clause should throw an IOException, and the catch clause should throw a TestException, passing the IOException to its constructor.

  7. Modify the catch block in Method2 that catches the TestException so that it displays the original cause of the exception. Compile and run the application to make sure it works.

Include in your program the following comments:
  • Name of program
  • Team's name with all the names of the members (e.g. Team A: John Doe, Jane Smith, etc.)
  • Current Date
  • Computer system and compiler you are using
  • Brief description of the program

Compile and run the Java program.

Take a screen capture by hitting simultaneously the keys Alt and Print Screen (Prt Sc) of the output results (console) and paste it in MS Paint. Save it as a gif file.

When you are ready, upload the java program and the gif file by clicking the link below:

Upload Lab

I cannot grade if I don't get the files and receive your email.