1Z0-803 · Question #175
Given: What is the result?
The correct answer is B. First Exception. The program executes a try-catch block where an inner try statement throws an exception with a specific message, which is then caught and printed to the console.
Question
Given:
What is the result?
Exhibit
Options
- A0
- BFirst Exception
- CSecond Exception
- DDone
- EThird Exception
How the community answered
(29 responses)- A3% (1)
- B72% (21)
- C14% (4)
- D7% (2)
- E3% (1)
Why each option
The program executes a try-catch block where an inner try statement throws an exception with a specific message, which is then caught and printed to the console.
The program does not output "0", as an exception is thrown and handled by printing its message, not an integer value.
An exception with the message "First Exception" is thrown within a 'try' block. The corresponding 'catch' block successfully intercepts this exception, and the 'getMessage()' method is invoked on the caught exception object, resulting in "First Exception" being printed. Since no further exceptions are thrown or re-thrown to alter the final output, this is the resulting display.
The exception with the message "Second Exception" is not thrown, or if it is, it's handled in a way that its message is not the final output.
The program does not reach a "Done" state that prints "Done" as its final output, as an exception's message is printed first and implies program termination or continuation without printing "Done".
The exception with the message "Third Exception" is not thrown in the provided code, so it cannot be the result.
Concept tested: Java exception handling flow
Source: https://docs.oracle.com/javase/tutorial/essential/exceptions/definition.html
Topics
Community Discussion
No community discussion yet for this question.
