This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
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!
Wayne L Johnson
Ranch Hand
Joined: Sep 03, 2003
Posts: 399
posted
0
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
Joined: Jul 15, 2003
Posts: 618
posted
0
Oh, sweet...thanks!
Joel McNary
Bartender
Joined: Aug 20, 2001
Posts: 1815
posted
0
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 ]
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
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