Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Throwing Customised Exception from Servlet (JRUN)

 
Sarath Mohan
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I want to display a customized Exception message from JRun Server whenever an exception occurs. I don't want to print the printStack on browser window.
throw new ServletException(msg) prints stackTrace.
I created my own Exception Class which extends the ServletException.
Then i coded
throw new MyException(msg) still it prints stackTrace.
Please share your ideas
Thanks
Bin
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you'd need to do is catch the exception, customized or not, and do not let your Servlet emit this exception. Because you are not actually letting the Exception make it to the servlet runner (in your case JRun), it doesn't produce one of those standardized error pages.

When you catch the exception, place the exception into the attribute space, and redirect (or forward, whichever makes more sense), to an error page.

This way, it looks 'normal' to the servlet runner, and on your error page, you have the choice of displaying the stack trace in white writing on a white background, or as an HTML comment, or not at all.
 
Sarath Mohan
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mike a lot
Got it
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic