benlogan1981
Programmer
Guys and Gals...
Ive been programming in Java for years, but I have never really fully understood why some method execution, (or at least debugging statements to the console) seems to take place/appear almost at random.
This has been highlighted again recently with a small app im developing just to test my knowledge of Java5. Its basically a small collection of classes that test various bits of new functionality in Java5 and outputs my results to the console; just for me to check I know what I'm doing!
Anyway, the ambigious behavior surrounds the exception testing. So, i have this class/constructor that gets called at the same place for each execution of the app, yet the debug statements appear at random locations within the overall output.
Is this behavior all done to how the VM handles exceptions? Any help would be appreciated...this is not a problem as such, just something I want to understand better
public class ExceptionTest {
public ExceptionTest(){
try{
//int temp = 5/0;
throw new Exception();
//System.out.println("No Problem Matey!");
}
catch(Exception e){
System.out.println("Exception on its way!");
e.printStackTrace();
}
finally{
// this will happen whether there is an exception or not!
System.out.println("Exception or not, lets finish here!");
}
}
}
Ive been programming in Java for years, but I have never really fully understood why some method execution, (or at least debugging statements to the console) seems to take place/appear almost at random.
This has been highlighted again recently with a small app im developing just to test my knowledge of Java5. Its basically a small collection of classes that test various bits of new functionality in Java5 and outputs my results to the console; just for me to check I know what I'm doing!
Anyway, the ambigious behavior surrounds the exception testing. So, i have this class/constructor that gets called at the same place for each execution of the app, yet the debug statements appear at random locations within the overall output.
Is this behavior all done to how the VM handles exceptions? Any help would be appreciated...this is not a problem as such, just something I want to understand better
public class ExceptionTest {
public ExceptionTest(){
try{
//int temp = 5/0;
throw new Exception();
//System.out.println("No Problem Matey!");
}
catch(Exception e){
System.out.println("Exception on its way!");
e.printStackTrace();
}
finally{
// this will happen whether there is an exception or not!
System.out.println("Exception or not, lets finish here!");
}
}
}