In this example we will show you how to use the try…catch statement in Java.
Source Code
package com.beginner.examples;
public class TryCatch {
public static void main(String[] args) {
// use the try...catch statement
try {
int[] nums = {3, 7, 15};
System.out.println(nums[9]);
} catch (Exception e) {
System.out.println("Error");
}
}
}
Output:
Error