I have a method with a try and catch block, and the code after the finally statement did not print ("end of a" line).
The method threw an exception and I suspect this is the reason. Is the reason for the line
System.out.println("end of a");
not printing because of the exception?
Here's the code:
Test Class:
public class Test
{
Integer num;
public Test(){
this(0) ;
System.out.println("Test constructor1 ");
}
public Test(int i){
if (i>0) num = new Integer(i) ;
System.out.println("Test constructor2 ");
}
public void a() throws Exception{
try{
if (num.intValue() > 0)
System.out.println("num = "+num.intValue());
System.out.println("executing a ");
throw new Exception();
}catch (Exception e){
System.out.println("exception caught in a");
if (e instanceof NullPointerException) throw e;
}
finally{
System.out.println("finally in a");
}
System.out.println("end of a");
}
}
Main Class:
public class MainTest2{
public static void main(String args[]){
try{
Test t2 = new Test();
t2.a();
System.out.println("executing main1 ");
}catch (Exception e){
System.out.println("exception caught in main");
}
System.out.println("ending main ");
}
}