File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Saving JavaMail error to .txt file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Saving JavaMail error to .txt file" Watch "Saving JavaMail error to .txt file" New topic
Author

Saving JavaMail error to .txt file

Eduardo Ponce de Leon
Ranch Hand

Joined: May 13, 2009
Posts: 99
Hi all,
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



Hope somebody can help me!!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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
Ranch Hand

Joined: May 13, 2009
Posts: 99
Paul,
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!!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

It's the variable you declare in your catch clause. You are catching the exception, aren't you?
Eduardo Ponce de Leon
Ranch Hand

Joined: May 13, 2009
Posts: 99
I havent declare anything... i just get this

on my console, when I run my program.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Here's the line of code which throws the exception:
at org.exjello.mail.ExchangeTransport.sendMessage(ExchangeTransport.java:120)

You're going to have to fix that so that you catch the exception which it throws.
Eduardo Ponce de Leon
Ranch Hand

Joined: May 13, 2009
Posts: 99
hmm.. I have no idea how to do that, but thanks!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

This page implies that the 507 error / status code you're getting (check the stack trace) means that your mailbox is full, or at least would be if your operation would succeed.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Eduardo Ponce de Leon
Ranch Hand

Joined: May 13, 2009
Posts: 99
I know is full...I made that on purpose.. My p problem is not that, my problem is how do I save that error to a .txt file.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

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
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Eduardo Ponce de Leon wrote:hmm.. I have no idea how to do that, but thanks!

Then show us the code for that method.
Eduardo Ponce de Leon
Ranch Hand

Joined: May 13, 2009
Posts: 99


After doing that then, every single exception will be saved to that file?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Eduardo Ponce de Leon wrote:

After doing that then, every single exception will be saved to that file?


Of course not. That code simply creates an exception and writes its stack trace to the log.
Eduardo Ponce de Leon
Ranch Hand

Joined: May 13, 2009
Posts: 99
ok. so if i know i will get this error eventualy

how do I make sure i log it to my error.txt file? This is what I ant to accomplish
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

I already told you. There is some code which writes the exception' stack trace to that "log" which you showed us. Change that code to write to your log as well.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Saving JavaMail error to .txt file