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

checking runtime errors

 
jonny alway
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello all, is there a way to get a log of all the errors that are displayed in the ms-dos box when an action is performed that causes an error?
its giving me a whole bunch of errors from the superclass names, but i think it displays what i need to know as one of the first ones that get wiped out of the screen
thanks
 
Mohan Panigrahi
Ranch Hand
Posts: 142
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jonny,
When you catch the exception, there instead of doing printStackTrace(), you can use the other two versions of this method, which accept a printWriter or a printStream object.
I tried writing some example and here is the code :

This would write over the log file every time the program is run.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jonny,
What you may want to do is simply redirect System.err to print to a text file rather than the console. The System class provides a method called setErr that allows you to do just that.This creates a text file called err.txt (you could name it anything you'd like) with these contents:
java.lang.Exception: Did this work?
at Whatever.main(Whatever.java:11)
If you'd like a further explanation of I/O in Java and to learn more about the java.io package, I recommend that you take a look at The I/O Lesson of Sun's Java Tutorial and just ask your questions here at JavaRanch.
Good Luck.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It occurs to me that you may also be interested in learning to use the new logging features of Java 1.4. Should that be the case, chapter 5 of JDK 1.4 Tutorial by Greg Travis covers logging in Java. This month, the book is being offered as a free download at http://www.javalobby.org/members/jdk14/index.jsp .
 
timothy zimmerman
Ranch Hand
Posts: 149
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you might also want to try simply redirecting your output from the command window.
java your_class 2> output.log
this should redirect the err output to the file output.log
I only have Windows 2000 here to verify it with, not sure if the command is compatible with older Windows (ie 9x)
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic