Java Source File
Download
public class NoCatch {
public static void main(String[] args) {
int a = 10;
int b = 3;
// No try-catch block, will throw an exception
// try {
// int result = a / b; // This will throw ArithmeticException
// System.out.println("Result: " + result);
// } catch (ArithmeticException e) {
// System.out.println("Umeweka 0 kwenye b: " + e.getMessage());
// }
try {
int[] numbers = { 1, 2, 3 };
System.out.println(numbers[5]);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println(" Caught : " + e.getMessage());
} finally {
// This ALWAYS runs
System.out.println(" Finally block executed . ");
System.out.println(" Cleanup done . ");
}
}
}