Use try and catch blocks to handle exceptions and prevent your program from crashing due to errors.
Source Code
try {
int[] numbers = {1, 2, 3};
System.out.println(numbers[10]);
} catch (Exception e) {
System.out.println("Something went wrong.");
}