You'll surround a section of code with a try block then immediately follow it with a catch block. Essentially, your code will try to execute the code in the try block. If something goes wrong, it jumps to the catch block instead.
In theory you can do something to try and resolve an error and change your program's behavior. But at the very least, you can print out an error message or a stack trace. This makes debugging easier and can stop your program from crashing.
Consider the example below. Assume some elements, like the array and scanner have already been declared and initialized appropriately.
int index = scan.nextInt(); // The user chooses an index
System.out.println(arr[index]); // Print out the specified index
System.out.println("Something went wrong.");
You can also write a catch statement that only handles a specific type of exception. Consider an alternate version of the catch block:
System.out.println("Invalid input - index out of bounds");