Results 1 to 2 of 2
Thread: novice question about output
- 02-05-2010, 12:33 PM #1
Member
- Join Date
- Feb 2010
- Posts
- 1
- Rep Power
- 0
novice question about output
Hi All.
I'm a novice (studing Java from a book and currently at Exception Handling chapter) and I have a simple question about the output result from running the following code (using netBeans IDE). Why do the println() statements in both the catch and finally block print the strings even before the printStackTrace() in the catch clause has finished printing on the screen?
and an exaple of the output...Java Code:public class simpleExample { public static void main(String[] args) { printDivision(10, 0); //Illegal division by 0 System.out.println("Exit from main()."); } public static void printDivision(int num, int den) { try { int result = computeDivision(num, den); System.out.println("Result = " + result); } catch (ArithmeticException ae) { ae.printStackTrace(); System.out.println("ArithmeticException handled in printDivision()."); } finally { System.out.println("finally done."); } System.out.println("Exit from printDivision()."); } public static int computeDivision(int num, int den) { return num/den; } }
Java Code:run: java.lang.ArithmeticException: / by zero ArithmeticException handled in printDivision(). finally done. Exit from printDivision(). at chapter6.simpleExample.computeDivision(simpleExample.java:23) Exit from main(). at chapter6.simpleExample.printDivision(simpleExample.java:11) at chapter6.simpleExample.main(simpleExample.java:5)
-
I'm no pro at this, but it appears to me that the program thread and the exception thread are different, so there is no way to guarantee which will complete first.
Similar Threads
-
java question output file
By dazednconfused in forum New To JavaReplies: 3Last Post: 09-17-2009, 03:07 PM -
Question about File renameTo() method : Abnormal output
By suvojit168 in forum New To JavaReplies: 1Last Post: 07-25-2009, 08:22 PM -
Java, output string, getting correct output? HELP!
By computerboyo in forum New To JavaReplies: 2Last Post: 02-25-2009, 11:44 PM -
CompSci 1 Novice, need some help
By annoyingzhang in forum New To JavaReplies: 9Last Post: 10-12-2008, 09:02 PM -
Hello to all, a java novice here, please help
By theneed4doyen in forum IntroductionsReplies: 5Last Post: 07-22-2008, 05:52 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks