N
Neroku
Hi, I'm trying to know if the finally block in a try-catch-finally
construction is always executed. Throwing another exception inside the
catch block doesn't seem to skip the finally block execution. But I
don't understand why, consider the following code:
class Example
{
public static void main(String []args)
{
try{
throw new Exception();
}catch(Exception e)
{
throw new RuntimeException("Hello");
}finally{
System.out.println("Finally Reached");
}
}
}
It always prints:
Finally Reached
When the exception inside the catch block is thrown, it should be
delivered to the java virtual machine, isn't it? so java should kill
this program at that point, but it does not.
Any ideas?
Is it possible to define the finally block and skip it during
execution?
TIA
construction is always executed. Throwing another exception inside the
catch block doesn't seem to skip the finally block execution. But I
don't understand why, consider the following code:
class Example
{
public static void main(String []args)
{
try{
throw new Exception();
}catch(Exception e)
{
throw new RuntimeException("Hello");
}finally{
System.out.println("Finally Reached");
}
}
}
It always prints:
Finally Reached
When the exception inside the catch block is thrown, it should be
delivered to the java virtual machine, isn't it? so java should kill
this program at that point, but it does not.
Any ideas?
Is it possible to define the finally block and skip it during
execution?
TIA