Grokking Java Interview Questions
Vote

0% completed

​

try, catch, finally, and Return Values

A program prints these two lines and ends normally:

charged 2400 cents main continues

Its method charge() contains one statement in its try block, and that statement throws an exception with the message card declined. No catch clause exists anywhere in the program. Why did the exception not reach main, and where did the number 2400 come from?

The answer is in the finally block of the method. The sections below follow the order of the three blocks, the rules for return values, the exceptions that can be lost, and the correct work of a catch block.

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content