File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes stange sequence of output in eclipse IDE Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "stange sequence of output in eclipse IDE" Watch "stange sequence of output in eclipse IDE" New topic

stange sequence of output in eclipse IDE

netto gaurav

Joined: Jan 29, 2008
Posts: 7
I'm trying to run a simple scenario but eclipse is giving me different output each time, refer to the code below -

sometimes I'm getting the output as below -
In catch
java.lang.NullPointerExceptionIn finally

at practice.exception1.main(

and at times -
In catch
In finally
at practice.exception1.main(

whereas as per my understanding the correct output should be -
In catch
at practice.exception1.main(
In finally

Am I missing something over here or is this some problem with eclipse. I tried running the program through command prompt and it worked fine (output as per my expectation)

Looking forward to a reply.

Kemal Sokolovic

Joined: Jun 19, 2010
Posts: 825

I believe that it's the result of the fact that writing to console is a slow operation (also blocking one). Did you try to redirect your output to file and see the result you get?

The quieter you are, the more you are able to hear.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15101

It's because the exception stack trace and what you print in your program using System.out.println() are sent to two different outputs: the exception is printed to stderr, while your System.out.println output is printed to stdout. You see in the Eclipse console that the exception message is in red, while your output is in black.

Those two output streams are separate, and Eclipse probably has two different threads to handle them, which print the result independently of each other in Eclipse's console window. Because that happens independently, the order in which the messages appear in the window isn't predictable (it depends on thread scheduling).

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
I agree. Here's the link:
subject: stange sequence of output in eclipse IDE
It's not a secret anymore!