Ask Question

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?

+1
Answers (1)
  1. 14 October, 21:28
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers