• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

stange sequence of output in eclipse IDE

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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





 
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
I'm not dead! I feel happy! I'd like to go for a walk! I'll even read a tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic