Objectives:
|
Students will:
|
Background:
|
Exceptions are conditions in a program that lead to a run time error. The default exception handler processes the exception and produces documentation of where the exception occurred and the exceptional condition. In Part I of this lab you will work with catching an exception and handling it using Java's try/catch structure In Part II of this lab you will work with avoiding an exceptions.. |
New Terms: |
try catch block - A Java structure that "tries" to execute a block of code and "catches" and handles exceptions if they arise. |
Materials:
|
You will write this program from scratch. |
Acknowledgment |
Elizabeth Adams and Nancy Harris |
1.
In your main method,
you should have 5 different "blocks" of code. Each block should lead
to one exception, then catch and handle that exception. To handle the
exception, you will print an appropriate message indicating the appropriate
data (echo the values) and the kind of exception generated.
2.
The exception should
not cause the program to fail; you must execute all five exceptions.
3.
Following the fifth
exception try catch block, you should print a statement saying Part I completed
successfully
1.
In your main method
you should have 3 more blocks of code which avoid the exception. For
each block you will print a message stating which exception could have occurred and how you avoided
it.
2.
The situation in each
block should not cause the program to fail; you must execute all three blocks
of code
3.
At the end of your
program you should print a statement saying "Program has ended
normally".