• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

capture printStackTrace even though void

 
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm getting a NullPointerException but I can't figure out where b/c calling toString on it doesn't tell me that. I figure I need printStackTrace, but that returns void, and I don't know how to access System.out and System.err stuff and print it out on my webpage that my JSP is outputting. I just need to capture the printStackTrace into a string so I can paste it on the webpage and figure out if it's going to tell me a line number in my code.
Thanks!
 
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For one of my web apps I've created an "Error.jsp" which is set as the "errorPage" of my other JSPs. Here's a snippet from "Error.jsp" that prints the exception and the StackTrace. You can pass either a PrintStream or PrintWriter to the "printStackTrace()" method, which is what I do here. Then I capture the contents of the writer and dump it to the screen.

The Traceback isn't formatted very nicely (since the browser ignores newline characters), but at least I get what I need.
Hope this helps ...
 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, sweet...thanks!
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If/since you're in a JSP, you could also throw a ServletException wrapped around your exception.
throw new ServletException(myException);
This will print the error on the page in a formatted way (with newlines translated as <br> ) . Note that the first error will be the ServletException; you will want to look beneath that where it will read "Root Cause:" and print out your problem exception there.
[ September 05, 2003: Message edited by: Joel McNary ]
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can also wrap a PrintWriter around the JspWriter and pass it directly to e.printStackTrace( new PrintWriter( out ) ), but I tend to use something very similar to Wayne.
You'll be hearing from my lawyers
 
reply
    Bookmark Topic Watch Topic
  • New Topic