Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
41 views2 pages

F4 - Rivera

The document discusses implementing exception handling in Java by creating a FindArray class that iterates through an array and catches ArrayIndexOutOfBoundsException, NullPointerException, and RuntimeException exceptions. It provides a code sample that throws these exceptions by accessing invalid array indexes and elements.

Uploaded by

Eustus Holmes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views2 pages

F4 - Rivera

The document discusses implementing exception handling in Java by creating a FindArray class that iterates through an array and catches ArrayIndexOutOfBoundsException, NullPointerException, and RuntimeException exceptions. It provides a code sample that throws these exceptions by accessing invalid array indexes and elements.

Uploaded by

Eustus Holmes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

COLLEGE OF COMPUTER STUDEIS

INFORMATION TECHNOLOGY DEPARTMENT

CCS0023L
(Object Oriented Programming)

Machine Problem

8
How to implement exception and assertion

Rollen Rivera.
Student Name:
AB21
Section:
Sir. Mark Sabili
Professor:
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.

public class Main {

public static void main(String[] args) {


String[] strings = {"a", "b", "c", null, "d"};

try {
for(int i=0; i<strings.length+1; i++) {
System.out.println(strings[i].toUpperCase ());
}

System.out.println(strings[10]);

}
catch(NullPointerException ne) {
System.out.println("Null pointer exception caught.");
}
catch(ArrayIndexOutOfBoundsException ae) {
System.out.println("Array idex out of bounds exception caught.");
}
catch(RuntimeException re) {
System.out.println("Runtime exception caught");
}
}

You might also like