GeeCON Prague 2014*
The moose likes JSP and the fly likes Error Page with Optional Stack Trace Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "Error Page with Optional Stack Trace" Watch "Error Page with Optional Stack Trace" New topic
Author

Error Page with Optional Stack Trace

rastin purr
Ranch Hand

Joined: Jul 20, 2002
Posts: 73
Dear All,
I'd like to have a page that display some business exception (eg. InsufficientFundException) with the possibility of displaying the stack trace of the business exception as well when clicking on a link (say for example). Say, the business exception (eg. InsufficientFundException) occurred and a page saying Insufficient Fund was displayed. There is a link at the bottom saying "click to display details" which would print out the exception stack trace. Is this possible? has anyone done this before? thanks for the help guys
Ras
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12792
    
    5
Since the exception information is long gone when the user sees the page, you will have to include it all in that page - possibly with Javascript to pop up an alert box with all of the stack trace. HINT - use <pre> to format the stack trace or it gets unreadable.
Bill
rastin purr
Ranch Hand

Joined: Jul 20, 2002
Posts: 73
Dear William,
Thanks for the reply. Could you explain further please? Prefereably with some code sample. Thanks a lot.
With Regards,
Ras
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

We either show the stack trace or we don't.
ie internal pages display the stack trace on the page, external (internet) page do not.
Personally I say that if you are going to show the exception, show it. Don't make it a 2 step process to get there.
Dave
rastin purr
Ranch Hand

Joined: Jul 20, 2002
Posts: 73
Hi David,
Can you explain a bit more about the internal pages and external pages you mentioned? Why would a web site need both pages? Thanks for the explanation in advance. Is there a way to make the two step process comes true? Thanks again
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

By internal and External I'm referring to pages viewed over the internet and pages that are only for internal, company use.
When we build a web-app that has an administration component, we print the stack trace on the internal admin pages, but never provide the stack trace to the outside world.
If you want to provide the stack trace in a two step process:
  • when the exception is detected, put it on the session and redirect to the error page.
  • if the user hits the button, call the page with an extra parameter.
  • when the parameter is detected, load the Exception from the session and display it


  • The reason I don't like doing things like this is that you are using the session to support request-scope data. The exception remains on the session even though it might never be used again by the user. You can't remove the exception in case they reload the page.
    Anyway, hope this helps.
    Dave
     
    GeeCON Prague 2014
     
    subject: Error Page with Optional Stack Trace