• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Different output while using printStackTrace()

 
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am executing following code:



I get different output in different runs.

optput

Computing average.
java.lang.ArithmeticException: Integer division by 0
at com.khalid.ch5.Average7.computeAverage(Average7.java:36)
at com.khalid.ch5.Average7.printAverage(Average7.java:20)
at com.khalid.ch5.Average7.main(Average7.java:7)
Finally in printAverage().
Exception handled in main().
Finally in main().
Exit main().


========================

java.lang.ArithmeticException: Integer division by 0
at com.khalid.ch5.Average7.computeAverage(Average7.java:36)
at com.khalid.ch5.Average7.printAverage(Average7.java:20)
at com.khalid.ch5.Average7.main(Average7.java:7)
Computing average.
Finally in printAverage().
Exception handled in main().
Finally in main().
Exit main().


=========================

Computing average.
java.lang.ArithmeticException: Integer division by 0
Finally in printAverage().
at com.khalid.ch5.Average7.computeAverage(Average7.java:36)
at com.khalid.ch5.Average7.printAverage(Average7.java:20)
at com.khalid.ch5.Average7.main(Average7.java:7)
Exception handled in main().
Finally in main().
Exit main().

==============================

Computing average.
Finally in printAverage().
Exception handled in main().
Finally in main().
Exit main().
java.lang.ArithmeticException: Integer division by 0
at com.khalid.ch5.Average7.computeAverage(Average7.java:36)
at com.khalid.ch5.Average7.printAverage(Average7.java:20)
at com.khalid.ch5.Average7.main(Average7.java:7)


I am assuming that a new thread is being spawned for printing stack trace, so depending upon main/new thread currently active, the output is displayed. I am using jdk 1.6. Is my assumption right?
 
Rancher
Posts: 1090
14
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The stack traces are going to System.err and System.out.println statements are going to System.out and both of them are dumping the content onto the same console. Each of these streams individually dump the content onto the same console without any consideration of the other stream. But within each stream, the messages will be printed in order.

HIH,
Chan.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic