I have a program that sends emails automatically. The only that I am missing is to catch error to a file... For example, sometims my server foler will ran out of space and I get this output in my console.
Basically what I want to catch is that when I get that type of error i know is a space issue and I need to empty my folder.
Currently I am loggin to a .txt file that I create using a printStream, do you have any tips...
so my intention is that
If I understand that correctly, you have caught an exception (let's suppose its variable name is "e"). And you have a PrintStream which you use for logging (let's suppose its variable name is "ps"). And you want to write the exception's stack trace to that PrintStream.
If that's all correct, then you just use the printStackTrace method.
Eduardo Ponce de Leon
Joined: May 13, 2009
ok. that makes sense..how do i declare that variable e, what should it be, an exception??
P.S. thanks for the link on my previous post, it was very helpful!!
Then please re-read Paul's first reply, although I'd go for a PrintWriter instead of a PrintStream:
- create a FileWriter for the file to write to
- create a PrintWriter around that FileWriter
- call printStackTrace for the exception using the PrintWriter as its argument
- close the FileWriter (or PrintWriter) in a finally clause