ACtE03 · Chapter 3Programming & Applications🏛️ Past Licensure QuestionID: 25a8d028
How many catch blocks can a single try block have in C++ / Java?
How many catch blocks can a single try block have in C++ / Java?
Multiple Choice Options
- A
Only 1
- B
Only 2
- C
Maximum up to 127
- D✓ Correct Option
As many as required
Detailed Technical Solution & Explanation
A single try block can be followed by multiple catch handlers to handle different types of exceptions independently (e.g., catching std::out_of_range, std::bad_alloc, or custom exceptions). There is no language-specified hard limit.
Option Analysis:
•
Option A (Only 1): Incorrect. Multiple catch blocks are routinely used for polymorphic exception handling.
•
Option B (Only 2): Incorrect. C++ and Java do not constrain catch blocks to two.
•
Option C (Maximum up to 127): Incorrect. There is no artificial language limit of 127 handlers.
•
Option D (As many as required): Correct. Developers may chain as many catch blocks as necessary to handle distinct exception types sequentially.
Reference: Mock Test 01NEC Licensure Syllabus