Question 01 of 05

Exception Handling

Write a Java program to demonstrate try-catch exception handling.

C++
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