✏️ Explanatory Question

Can one catch block sufficiently trap and handle multiple exceptions?

👁 25 Views
📘 Detailed Answer
🔴 Hard
💡

Answer with Explanation

Yes, one catch block can handle multiple exceptions by using the multi-catch syntax (introduced in Java 7):


catch (IOException | NumberFormatException e) {
   System.out.println(e.getMessage());
}