Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to write exceptions in a log file

Status
Not open for further replies.

lipi123

Programmer
May 1, 2005
2
US
Hi,

How to write exceptions in a log file. Can anybody give me a sample file.


Thanks
 
ex.printStackTrace(outputStream);

where ex is your exception object, and outputStream is a FileOutputStream previously opened.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Hi,
I have written the following code in catch block

catch (Exception e)
{
OutputStream bos = new FileOutputStream("Log");
e.printStackTrace(bos);
}


I am getting the following error, when I execute the above code:

dbUpload2.java:106: cannot find symbol
symbol : method printStackTrace(java.io_OutputStream)
location: class java.lang.Exception
e.printStackTrace(bos);
 
Try this :


catch (Exception e)
{
PrintWriter pw = new PrintWriter(new FileOutputStream("Log"));
e.printStackTrace(pw);
}

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top