Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2008

Tip: Looking for answers? Try searching our database.

Redirect stack trace to a string

Thread view: 
Sylvain - 05 Mar 2008 10:52 GMT
Hi !

I would like to be able to log for an exception, not only the e.getMessage()
but the whole e.printStackTrace(). Does anybody know how to redirect
temporarily the standard out to a string ?

Ideal would be such a function :
- store the standard out
- change the standard out to a string reader
- execute the e.printStackTrace()
- log the output string
- restore the standard out

Thank you for your help

Best regards

Sylvain Caillet
Silvio Bierman - 05 Mar 2008 11:31 GMT
> Hi !
>
[quoted text clipped - 14 lines]
>
> Sylvain Caillet

Use printStackTrace(PrintWriter w) ?
Sylvain - 06 Mar 2008 08:32 GMT
Thank you.
Sylvain

>> Hi !
>>
[quoted text clipped - 16 lines]
>
> Use printStackTrace(PrintWriter w) ?
Real Gagnon - 05 Mar 2008 18:55 GMT
> I would like to be able to log for an exception, not only the
> e.getMessage() but the whole e.printStackTrace(). Does anybody know
> how to redirect temporarily the standard out to a string ?

You don't need to do that. Just attach a StringWriter to a PrintWriter and
use the appropriate e.printStackTrace().

Example at http://www.rgagnon.com/javadetails/java-0029.html

Bye.
Signature

Real Gagnon  from  Quebec, Canada
* Java, Javascript, VBScript and PowerBuilder code snippets
* http://www.rgagnon.com/howto.html
* http://www.rgagnon.com/bigindex.html

Sylvain - 06 Mar 2008 08:32 GMT
thank you. It works fine.
Sylvain

>> I would like to be able to log for an exception, not only the
>> e.getMessage() but the whole e.printStackTrace(). Does anybody know
[quoted text clipped - 6 lines]
>
> Bye.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.