Hi,
I was trying to execute the following codes, but the something that I don't undestand was happen. The program was compiled differently according to ouput picture of the program in my java book. Furthermore, then I tried to compile the program in eclipse and NetBeans. I saw that all of output are different each other. I think output of the book is sensible, but I couldn't see this output on the compilers. Can anybody explain this stutation? What is the problem?
package finallyblock; public class FinallyBlock { public static void main(String[] args) { try{ throwException(); } catch(Exception exception){ System.err.println("Exception handled in main"); } doesNotThrowException(); } public static void throwException() throws Exception{ try{ System.out.println("Method throwException"); throw new Exception(); } catch(Exception exception){ System.err.println("Exception handled in method throwException"); } finally{ System.err.println("Finally executed in throwException"); } } public static void doesNotThrowException(){ try{ System.out.println("Method doesNotThrowException"); } catch(Exception exception){ System.err.println(exception); } finally{ System.err.println("Finally executed in doesNotThrowException"); } System.out.println("End of method doesNotThrowException"); } }
The output In My Book:
Method throwException
Exception handled in method throwException
Finally executed in throwException
Exception handled in main
Method doesNotThrowException
Finally executed in doesNotThrowException
End of method doesNotThrowException
The output On NetBeans:
Method throwException
Method doesNotThrowException
Exception handled in method throwException
End of method doesNotThrowException
Finally executed in throwException
Finally executed in doesNotThrowException
The output On Eclipse:
Method throwException
Exception handled in method throwException
Finally executed in throwException
Method doesNotThrowException
End of method doesNotThrowException
Finally executed in doesNotThrowException