I have a simple Arithmetic Program typed in Eclipse. When run the program in Eclipse the output appears in weird order each time I run. Sometimes The exception comes at last print statement comes first (which is the right way). Some times it comes vise-versa in a jumbled up order. Why it is happening & how to rectify it? Is there any setting to make it print in a right way each time I execute. The below screen shots show how it appears. Please help me rectify this problem.
Correct Order:

Incorrect Order when we run couple times after

package com;
public class Abc {
/**
* @param args
*/
public static void main(String[] args) {
System.out.println("begin main");
// TODO Auto-generated method stub
int a = 10;
int b = 0;
int c = 0;
System.out.println("value of a BD is " + a);
System.out.println("value of b BD is " + b);
System.out.println("value of c BD is " + c);
c = a/b; //Arthmetic Exception
System.out.println("value of a AD is " + a);
System.out.println("value of b AD is " + b);
System.out.println("value of c AD is " + c);
}
}
Two different streams are being used here. You are using System.out. and the exception is printed with System.err. They are buffered, so one's output may print before the other's.
You can call System.out.flush(); before the exception line:
System.out.flush();
c = a/b; //Arthmetic Exception
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With