File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Saving JavaMail error to .txt file

 
Eduardo Ponce de Leon
Ranch Hand
Posts: 99
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20203
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 99
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20203
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's the variable you declare in your catch clause. You are catching the exception, aren't you?
 
Eduardo Ponce de Leon
Ranch Hand
Posts: 99
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I havent declare anything... i just get this

on my console, when I run my program.
 
Paul Clapham
Sheriff
Pie
Posts: 20203
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 99
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmm.. I have no idea how to do that, but thanks!
 
Rob Spoor
Sheriff
Pie
Posts: 20393
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Eduardo Ponce de Leon
Ranch Hand
Posts: 99
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20393
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20203
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 99
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


After doing that then, every single exception will be saved to that file?
 
Paul Clapham
Sheriff
Pie
Posts: 20203
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 99
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20203
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic