Home / Questions / Can one catch block sufficiently trap and handle multiple exceptions?
Explanatory Question

Can one catch block sufficiently trap and handle multiple exceptions?

👁 22 Views
📘 Detailed Answer
🕒 Easy to Read
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.

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());
}