Can one catch block sufficiently trap and handle multiple exceptions?

Long Answer
Views 20

Answer:

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

Related Articles:

This section is dedicated exclusively to Questions & Answers. For an in-depth exploration of Java Programming Language, click the links and dive deeper into this subject.

Join Our telegram group to ask Questions

Click below button to join our groups.