wood burning stoves 2.0*
The moose likes I/O and Streams and the fly likes A simpleIORedirector,but it did not works Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "A simpleIORedirector,but it did not works" Watch "A simpleIORedirector,but it did not works" New topic
Author

A simpleIORedirector,but it did not works

Tracy Tse
Greenhorn

Joined: May 24, 2010
Posts: 22
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!


Whatever it takes is what i have got !
Lift is the best sitcom!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41621
    
  55
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?


Ping & DNS - my free Android networking tools app
Tracy Tse
Greenhorn

Joined: May 24, 2010
Posts: 22
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
Marshal

Joined: Mar 22, 2005
Posts: 41621
    
  55
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

Joined: May 24, 2010
Posts: 22
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!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: A simpleIORedirector,but it did not works