• Post Reply Bookmark Topic Watch Topic
  • New Topic

Order of try,catch and finally  RSS feed

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Team,
I am Running simple Program which causes Runtime Exception like


Here i have a little bit confusion The Order of the output statements

i am getting different outputs in different attempts like
1)Try Block
ERROR/ by zero
Finally Block

2)ERROR/ by zero
Try Block
Finally Block

3)Try Block
Finally Block
ERROR/ by zero


 
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're printing to two different streams, System.out and System.err. They aren't synchronized.

Change the code so that all output is to one of the two and you'll get consistent results.
 
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to clarify...

System.out is one way to get data out of your application. System.out is another. By default, both happen to print to the screen. However, there is nothing that says "first print all of THESE, and then print all of THOSE." So, they come out in a random order.

so change all of them to System.out, so that all messages go along the same path to the screen, and they should be printed in order.

After all, one of the primary tenets of debugging is to reduce as many variables as possible. Using two streams for output introduces an unnecessary one that just confuses the issue (as you are learning).
 
S.Reddisekhar Reddy
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good dude,Thanks
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!