1Z0-803 · Question #165
Which three statements are true regarding exception handling in Java?
The correct answer is B. A try block can be followed by a catch or finally block. C. In multiple catch blocks, the superclass catch handler must be caught after the subclass catch F. Any Exception subclass can be used as the parent class of a user-defined exception.. This question tests understanding of fundamental Java exception handling rules regarding the structure of try-catch-finally blocks, the order of catch blocks, and the creation of custom exceptions.
Question
Which three statements are true regarding exception handling in Java?
Options
- AA try block can be followed by multiple finally blocks.
- BA try block can be followed by a catch or finally block.
- CIn multiple catch blocks, the superclass catch handler must be caught after the subclass catch
- DAn unchecked exception must be caught explicitly.
- EA finally block can be written before the catch block.
- FAny Exception subclass can be used as the parent class of a user-defined exception.
How the community answered
(34 responses)- A6% (2)
- B91% (31)
- E3% (1)
Why each option
This question tests understanding of fundamental Java exception handling rules regarding the structure of try-catch-finally blocks, the order of catch blocks, and the creation of custom exceptions.
A try block can be followed by at most one finally block, not multiple.
A try block must always be followed by at least one catch block or one finally block to handle potential exceptions or ensure cleanup code execution.
When multiple catch blocks are used, more specific exceptions (subclasses) must be caught before more general exceptions (superclasses) to avoid unreachable code compilation errors.
Unchecked exceptions, which are subclasses of `RuntimeException` or `Error`, do not require explicit catching and can be left unhandled.
The finally block must always appear after all catch blocks or directly after the try block if no catch blocks are present.
User-defined exceptions are created by extending the `Exception` class or any of its existing subclasses, providing a hierarchical structure for custom error types.
Concept tested: Java exception handling syntax and hierarchy
Source: https://docs.oracle.com/javase/tutorial/essential/exceptions/definition.html
Topics
Community Discussion
No community discussion yet for this question.