MILITARY COLLEGE OF SIGNALS
SOFTWARE CONSTRUCTION
Lab Submission: 08
Name: Zahra Qamar
Course: BESE 23C
Experiment # 8: Exception Handling
1. Objectives:
(a). Program exceptions
(b). Exception handling using Try Catch blocks
(c). Creating and handling own exceptions
2. Time Required: 3 hrs
3. Programming Language: Java
4. Software Required:
(a). Windows OS
(b). Netbeans (7.4)/Eclipse Kepler
The basic concept of exception handling is given in the class lecture slides. Following is an
example taken from the slides.
An Error “indicates serious problems that a reasonable application should not try to
catch.”
Task 1: For the registration of a student to online library, there is a registration form with basic
details. You are required to create your own exceptions to be raised if the data for the above form
in invalidated. In this task you make the exceptions and test your exceptions by a simple driver
program. You are not required to create the form or to link the exceptions with the form.
Task 2: Write a program that shows that the order of catch blocks is important. If you try to
catch a superclass exception type before a subclass type, the compiler should generate errors.
Task 3: Write a program that shows a constructor passing information about constructor failure
to an exception handler. Define class SomeException, which throws an Exception in the
constructor. Your program should try to create an object of type SomeException and catch the
exception that is thrown from the constructor.
Task 4: Write a program that illustrates rethrowing an exception. Define methods someMethod
and someMethod2. Method someMethod2 should initially throw an exception. Method
someMethod should call someMethod2, catch the exception and rethrow it. Call someMethod
from method main, and catch the rethrown exception. Print the stack trace of this exception.