Ask Question
9 January, 19:53

When multiple exceptions are caught in the same try statement and some of them are related through inheritance, does the order in which they are listed matter?

+2
Answers (1)
  1. 9 January, 22:56
    0
    Yes, the order in which the catch blocks are listed matter in case where multiple exceptions are caught in the same try statement and some of them are related through inheritance.

    Explanation:

    A try block may be followed by one or mutiple catch blocks. Each catch block should contain a separate exception handler. Thus, if we need to perform different tasks for the occurrence of different exceptions then we need to use java multiple catch blocks.

    Every catch block should be ordered from the most particular to the most generic like catch for the NumberFormatException class must come before the catch for the Exception class.

    Thus, the order in which the catch blocks are listed matter in case where multiple exceptions are caught in the same try statement and some of them are related through inheritance.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “When multiple exceptions are caught in the same try statement and some of them are related through inheritance, does the order in which ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers