Exams Knowledge Hub

MCQs for Competitive Exams, School & College Exams

Module: | Classes, Objects, OOPs & Inheritance

Q44: Consider the following statements regarding Try-Catch blocks and Multiple Catch rules:

1. When a try block is followed by multiple catch blocks, the Java Virtual Machine evaluates the catch blocks simultaneously on parallel threads to immediately find the matching exception type.
2. If multiple catch blocks are utilized, the compiler strictly mandates that catch blocks handling specific child subclasses (e.g., FileNotFoundException) must physically precede catch blocks handling their broader parent classes (e.g., IOException).
3. Java 7 introduced the multi-catch block feature, allowing a single catch block to safely handle multiple unrelated exceptions separated by the bitwise OR operator (|).

Which of the above statements is/are correct?
A
Only 1 and 2
B
Only 1 and 3
C
Only 2 and 3
D
1, 2, and 3
✅ Correct Answer: C
🎯 Quick Answer:
The correct combination is 2 and 3. Statement 1 is incorrect because the JVM evaluates multiple catch blocks strictly sequentially, top-to-bottom, stopping completely at the first matching catch block it encounters on the primary execution thread.
Concept Definition: A try block encloses risky code, while catch blocks provide specific recovery procedures depending on the exact type of exception thrown.
Structural Breakdown: A multi-catch block uses the syntax 'catch (IOException | SQLException e)'. Multiple sequential catch blocks look like 'catch (ExceptionA e) {} catch (ExceptionB e) {}'. Historical/Related Context: Before Java 7's multi-catch feature, developers who needed to execute the exact same recovery logic (like logging an error) for three different exceptions had to write three entirely separate, identical catch blocks, severely violating the DRY (Don't Repeat Yourself) principle.
Causal Reasoning: Child subclasses must strictly precede parent classes (Statement 2) due to polymorphism.
If the generic 'Exception' parent catch block was placed first, it would dynamically catch absolutely everything.
Any subsequent subclass catch blocks beneath it would become mathematically unreachable, triggering a fatal Unreachable Code compilation error.