Please help!..redirecting error messages

I'm developing an application and I wish to redirect all error messages to a separate .txt file. Is this possible?This is very urgent, if anyone can help!Thanks.
[183 byte] By [MUGGINS20a] at [2007-9-28 14:46:18]
# 1
You could create some sort of handler class. Each time an exception is thrown you could pass the error to your handler class from with the catch block. You can then do what ever you want with it. Output the results to a file, send them in an email somewhere etc.
jrsansoma at 2007-7-12 11:21:46 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 2

String sSysLog = "MySystemLogFile.txt";

PrintStream stream = new PrintStream(new FileOutputStream(sSysLog, true), true);

System.setErr(stream);// Set System.err to output to specified log file.

rconnera at 2007-7-12 11:21:46 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 3
FileOutputStream err = new FileOutputStream("stderr.log");PrintStream errPrintStream = new PrintStream(err);System.setErr(errPrintStream);
dvohra09a at 2007-7-12 11:21:46 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...