Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A simpleIORedirector,but it did not works

 
Tracy Tse
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all, i wrote a simple programm ,initially it worked fine,but after i added a line(line 54 and its surrounding try-finally block) ,things went unexpected.
Here is my code with some comments attached.

i just explicitly thrown an exception and wanted to check the exception result in my output file .nevertheless ,there was nothing related to exception messages
but the source code lines.

Thanks in advance!
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What did you expect the file to contain? At a quick glance, the code produces no output except what the user types in. The IOException is ignored - did you mean to add a catch block that cause something to be written to Stdout or Stderr?
 
Tracy Tse
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:What did you expect the file to contain? At a quick glance, the code produces no output except what the user types in. The IOException is ignored - did you mean to add a catch block that cause something to be written to Stdout or Stderr?

well,actually, in my mind ,the statement will write exception infos to the stderr which is redirectied to a file called
exception.txt hard-coded in my program, plus, i did not want to add a catch a block and write the exception messages on my own!

Thanks. Do you have any idea why this ?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in my mind ,the statement throw new IOException(); will write exception infos to the stderr which is redirectied to a file called exception.txt hard-coded in my program

It does not. By having a try/finally, the code is catching the exception, but not doing anything with it.
 
Tracy Tse
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:
in my mind ,the statement throw new IOException(); will write exception infos to the stderr which is redirectied to a file called exception.txt hard-coded in my program

It does not. By having a try/finally, the code is catching the exception, but not doing anything with it.


Gotcha, i probably should write the statement within my catch block . Many thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic