Вы находитесь на странице: 1из 4

COLLEGE OF COMPUTER STUDEIS

INFORMATION TECHNOLOGY DEPARTMENT

CCS0023L
(Object Oriented Programming)

EXERCISE

8
Handling Java Exception and Assertion

<BLANDO, Rouge Mikhael J.>


<R21 >
<10/16/2019 >
I. OBJECTIVES:

At the end of the experiment, students must be able to:

Cognitive:
a) Know how to use handle exceptions using try-catch-finally constructs
b) Learn how to create existing and customized exceptions
c) Learn how to differentiate between checked and unchecked exceptions
d) Learn how to throw exceptions programmatically

Psychomotor:
a) construct a program to handle unusual conditions that interrupt the normal operation of
the program
b) compile and debug the error of the program

Affective
a) appreciate the concept behind this experiment

II. BACKGROUND INFORMATION

 Exceptional conditions sometimes occur in properly written code and must be handled.
 Exception handling in Java is build around the “throw-and-catch” paradigm.
 All exceptions are objects of Throwable class. “try-catch()-finally” statement is the
exception handling mechanism of Java. “throw” statement manually creates an exception
or rethrows an exception, “throws” statement allows propagation of exception to the call
stack

III.EXPERIMENTAL PROCEDURE:

1. Arabic to Roman Numeral Converter -> Roman Numeral to Arabic Converter


Ex. 1234 = MCCXXXIV
MCCXXXIV = 1234
Notes:
a. Valid values must range from 1 to 3999
b. Invalid values (numbers out of the given range above) must be trapped
c. Invalid non-numeric values (ex. 123D) should be trapped
d. Invalid numeric and non-numeric values should have specific ERROR MESSAGES

2. Arabic Numbers to Words Converter


Ex. 1234 = One Thousand Two Hundred Thirty-Four Notes:
a. Valid values must range from 1 to 3999
b. Invalid values (numbers out of the given range above) must be trapped
c. Invalid non-numeric values (ex. 123D) should be trapped
d. Invalid numeric and non-numeric values should have specific ERROR MESSAGES

3. Create a Class FindArray that will try to iterate in the array displaying the content
in each index. The program should be able to catch an
ArrayIndexOutOfBoundsException, a NullPointerException and a
RunTimeException.
V. QUESTION AND ANSWER:

1. What exception types can be caught by the following handler?

catch (Exception e) {

______________________________________________________________________________
______________________________________________________________________________
_____________________________________________________________________________

2. Is there anything wrong with the following exception handler as written? Will this code
compile?
try {

} catch (Exception e) {

} catch (ArithmeticException a) {

______________________________________________________________________________
______________________________________________________________________________
_____________________________________________________________________________

3. Is the following code legal?

try {

} finally {

_____________________________________________________________________________
______________________________________________________________________________
_____________________________________________________________________________
Topic Exception
Lab Activity No 8a
Lab Activity Arabic to Roman Numeral
Converter
CLO 1,3
Program execution (20)
Correct output (20)
Design of output (10)
Design of logic (20)
Standards (20)
Delivery (10)
TOTAL

Topic Exception
Lab Activity No 8b
Lab Activity Arabic Numbers to Word
Converter
CLO 1,3
Program execution (20)
Correct output (20)
Design of output (10)
Design of logic (20)
Standards (20)
Delivery (10)
TOTAL

Topic Exception
Lab Activity No 8c
Lab Activity FindArray
CLO 1,3
Program execution (20)
Correct output (20)
Design of output (10)
Design of logic (20)
Standards (20)
Delivery (10)
TOTAL