Which statement is FALSE about catch{} blocks?

  1. There can be several catch{} blocks in a try/catch structure.

  2. The catch{} block for a child exception class must PRECEED that of a parent execption class.

  3. The catch{} block for a child exception class must FOLLOW that of a parent execption class.

  4. If there is no catch{} block there must be a finally{} block.


Correct Option: C
Explanation:

To answer this question, the user needs to have knowledge of the try-catch-finally error handling mechanism in programming.

Option A: This statement is true. We can have several catch{} blocks in a try/catch structure in order to handle different types of exceptions.

Option B: This statement is true. The catch{} block for a child exception class must precede that of a parent exception class because if a child exception is caught by a parent catch{} block, the catch{} block for the child exception will never be executed.

Option C: This statement is false. The catch{} block for a child exception class must follow that of a parent exception class. This is because if the catch{} block for a child exception class precedes that of a parent exception class, the parent catch{} block will catch the exception first and the child catch{} block will never be executed.

Option D: This statement is false. If there is no catch{} block, there does not necessarily have to be a finally{} block. A finally{} block is optional and is used to execute code regardless of whether an exception was thrown or not.

Therefore, the answer is:

The Answer is: C

Find more quizzes: