A single try block can have several catch blocks, each handling a different exception type:
try {
String[] args = {"abc"};
int index = Integer.parseInt(args[0]);
int value = args[index].length();
} catch (NumberFormatException e) {
System.out.println("Not a number");
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Index out of range");
}
Java checks each catch block from top to bottom and enters the first one whose type matches the thrown exception. Only one catch block runs. After it finishes, execution continues after the entire try-catch structure.
Order matters. If you put a parent class before a child class, the child block becomes unreachable and the compiler rejects your code.