Can you catch multiple exceptions in a single catch block?
January 16, 2025
Yes, since Java 7, multiple exceptions can be caught using a single catch block with a pipe (|).
try {
int result = Integer.parseInt(“abc”);
} catch (NumberFormatException | NullPointerException e) {
System.out.println(“Exception caught: ” + e);
}