jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes checking runtime errors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "checking runtime errors " Watch "checking runtime errors " New topic

checking runtime errors

jonny alway

Joined: Jun 12, 2002
Posts: 2
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
Mohan Panigrahi
Ranch Hand

Joined: Sep 28, 2001
Posts: 142
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

Joined: Dec 10, 2001
Posts: 7023
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.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
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

Joined: Jun 26, 2001
Posts: 149
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
subject: checking runtime errors
It's not a secret anymore!