how to write exception information into a txt file?
i got a program which generate lots of exception information. its hard to see from the screen, is there any way to make the input into some txt file?
when i use
try
{
...
}catch(Exception ex)
{
// to do something here and make the output into a txt file?
}
[314 byte] By [
JbloodHa] at [2007-10-2 17:16:21]

depending upon the version of jdk being used one of the options will be to fetch the StackTraceElement array and writing each of the element using the standard file io operation
StackTraceElement[] elements = ex.getStackTrace();
int noOfElements = elements.length;
for (int i=0; i<noOfElements;i++)
{
//fetch the stacktrace element and write to a file.
}
Thanks
Rahul>
my sdk version is jdk1.5.0_06
when u said "//fetch the stacktrace element and write to a file"
i tried this
StackTraceElement[] elements = ex.getStackTrace();
int noOfElements = elements.length;
for (int i=0; i<noOfElements;i++)
{
fetchErrToLog(elements); // this method is to write string into a file
}
and then it ask me to include another try{}catch(){} to cover the fetchErrToLog() method.... and seems it not working too>
You can redirect the standard output and standard error streams into files. See the example above for how to do it from the starting environment (prompt/shell).
Besides, you can programatically reassign stdout and stderr.
// java.lang.System
public static void setOut(PrintStream out)
//Reassigns the "standard" output stream.
public static void setErr(PrintStream err)
//Reassigns the "standard" error output stream.