Ask Question
25 July, 07:39

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?

+4
Answers (1)
  1. 25 July, 09:21
    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?
Get 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 & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers