aspose file tools*
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 Soft Skills 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
Author

stange sequence of output in eclipse IDE

netto gaurav
Greenhorn

Joined: Jan 29, 2008
Posts: 7
Hi,
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(exception1.java:9)

and at times -
In catch
In finally
java.lang.NullPointerException
at practice.exception1.main(exception1.java:9)


whereas as per my understanding the correct output should be -
In catch
java.lang.NullPointerException
at practice.exception1.main(exception1.java:9)
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.
Thanks





Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

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: 14430
    
  23

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
 
 
subject: stange sequence of output in eclipse IDE