Originally posted by stephen shields:
this does seem like a homework assignment.
in my limited knowledge, yes they are the same. finally just says to execute this code if an exception is after all exceptions are by passed.
if an exception is caught, all work following it will not occur
If a meteor hits the machine
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Ken Blair wrote:
Originally posted by stephen shields:
this does seem like a homework assignment.
in my limited knowledge, yes they are the same. finally just says to execute this code if an exception is after all exceptions are by passed.
if an exception is caught, all work following it will not occur
Once again, no they are not the same. Under normal circumstances code in a finally block will always execute. If the try block completes normally it will be executed. If the try block throws an exception, it will still execute. If the exception is caught by a catch block, it will still execute. If an exception is caught by a catch block and the catch block throws another exception, it will still execute.
Nothing can cause a finally block to be skipped, however an infinite number of possibilities can cause the JVM to terminate before the finally block can be executed. If a meteor hits the machine, or the power goes off, or the processor blows up, or there's a call to System.exit(), or the application is suddenly terminated, etc. the finally block may not be executed, but there's nothing you can do about that.
:d
pooja jain wrote:
i dont get it.
System.exit() will terminate the JVM but it's true for both the cases.
pooja jain wrote:
so 1st & 2nd code is same.
pooja jain wrote:
finally will execute in all cases (except JVM crashes) and in first code, mustExecute() will also execute in all cases.
We know that one of them, sadly, has died.Henry Wong wrote:And that maybe many of the participants have moved on?
:d
pooja jain wrote:@henry
Right, but only the first case has a finally -- so in the second case it is possible for mustExecute() to not execute.
in what circumstances, it's possible for mustExecute() to not execute? that is what my confusion is.
Henry Wong wrote:
pooja jain wrote:@henry
Right, but only the first case has a finally -- so in the second case it is possible for mustExecute() to not execute.
in what circumstances, it's possible for mustExecute() to not execute? that is what my confusion is.
1. errorProne() throws an Error.
2. errorProne() throws an exception, which is followed by toHandle() throws an Error.
3. errorProne() throws an exception, which is followed by toHandle() throws a runtime exception.
Henry
:d
Won't you please? Please won't you be my neighbor? - Fred Rogers. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|