Results 1 to 2 of 2
  1. #1
    GarBage is offline Member
    Join Date
    Feb 2010
    Rep Power

    Default 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?

    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) {
    			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;
    and an exaple of the output...

    Java Code:
    java.lang.ArithmeticException: / by zero
    ArithmeticException handled in printDivision().
    finally done.
    Exit from printDivision().
            at chapter6.simpleExample.computeDivision(
    Exit from main().
            at chapter6.simpleExample.printDivision(
            at chapter6.simpleExample.main(

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power

Similar Threads

  1. java question output file
    By dazednconfused in forum New To Java
    Replies: 3
    Last Post: 09-17-2009, 03:07 PM
  2. Question about File renameTo() method : Abnormal output
    By suvojit168 in forum New To Java
    Replies: 1
    Last Post: 07-25-2009, 08:22 PM
  3. Java, output string, getting correct output? HELP!
    By computerboyo in forum New To Java
    Replies: 2
    Last Post: 02-25-2009, 11:44 PM
  4. CompSci 1 Novice, need some help
    By annoyingzhang in forum New To Java
    Replies: 9
    Last Post: 10-12-2008, 09:02 PM
  5. Hello to all, a java novice here, please help
    By theneed4doyen in forum Introductions
    Replies: 5
    Last Post: 07-22-2008, 05:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts