Cycle 03
Lab Cycle 3 — Advanced Java
Exception Handling
Problem Statement
Write a Java program to demonstrate try-catch exception handling.
public class ExceptionDemo {
public static void main(String[] args) {
try {
int[] arr = {1, 2, 3};
System.out.println(arr[5]);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Index out of bounds!");
} finally {
System.out.println("Finally block executed");
}
}
}
Question 1 of 5